小程序-报错 xxx is not defined (已解决)
问题情境:
这样一段代码,微信的小程序报错 is not defined
我 wxml 想这样调用
//wxml 代码<view class='ltext'>{{_typeTitle}}</view>
- 1
- 2
我出错的情况是这样的
//程序 js 代码Page({data: { titleArray: ['01 某试玩平台', ‘02 某试玩平台’,'03 ...' ],},onLoad: function (options) { var that = this; var _typeTitle = titleArray[1]; that.setData({ _typeTitle: _typeTitle, })},})
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
为什么在 data 里定义了,还是不能用呢
这是,新手在学习时,常见错误之一,不能直接使用 名字调用
正确的方式
//程序 js 代码Page({data: { titleArray: ['01 某试玩平台', ‘02 某试玩平台’,'03 ...' ],},onLoad: function (options) { var that = this; var _typeTitle = this.data.titleArray[1]; that.setData({ _typeTitle: _typeTitle, })},})
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17