問題情境:
這樣一段代碼,微信的小程序報錯 is not defined小程序
我 wxml 想這樣調用微信
//wxml 代碼 <view class='ltext'>{{_typeTitle}}</view>
我出錯的狀況是這樣的學習
//程序 js 代碼 Page({ data: { titleArray: ['01 某試玩平臺', ‘02 某試玩平臺’,'03 ...' ], }, onLoad: function (options) { var that = this; var _typeTitle = titleArray[1]; that.setData({ _typeTitle: _typeTitle, }) }, })
爲何在 data 裏定義了,仍是不能用呢this
這是,新手在學習時,常見錯誤之一,不能直接使用 名字調用code
正確的方式xml
//程序 js 代碼 Page({ data: { titleArray: ['01 某試玩平臺', ‘02 某試玩平臺’,'03 ...' ], }, onLoad: function (options) { var that = this; var _typeTitle = this.data.titleArray[1]; that.setData({ _typeTitle: _typeTitle, }) }, })