Applet error: XXX is not defined (How to Solve)

Applet – error XXX is not defined (resolved)

Problem situation:
for such a piece of code, the error reported by wechat applet is not defined

I wxml want to call

//wxml code
<view class='ltext'>{{_typeTitle}}</view>

I make mistakes like this


Page({
data: {
    titleArray: ['01 A trial platform', ‘02 A trial platform’,'03 ...' ],
},

onLoad: function (options) {
    var that = this;
    var _typeTitle = titleArray[1];
  
    that.setData({
         _typeTitle: _typeTitle, 
   })
},
})

why is it defined in data, but it can’t be used?

This is one of the common mistakes when novices learn. They can’t call directly by name

correct method

Page({
data: {
    titleArray: ['01 A trial platform', ‘02 A trial platform’,'03 ...' ],
},

onLoad: function (options) {
    var that = this;
    var _typeTitle = this.data.titleArray[1];


 that.setData({
         _typeTitle: _typeTitle, 
   })
},
})

 

Similar Posts: