*1、小程序用setTimeOut函数时间,this很容易找不到方向。所以需要在执行setTimeOut之前将this定义后指定好。要在前面加上const that = this;然后将延时函数里面的this换成that
例如:
Page({
/**
* 页面的初始数据
*/
data: {
name:
"0",
},
/**
* 生命周期函数--监听页面加载
*/
onLoad:
function (options) {
this.count_down();
},
count_down:
function () {
const that =
this;
setTimeout(
function () {
that.setData({ name:
"1523" })
},
2000)
},
*2、小程序的页面跳转函数
wx.navigateTo({
url:
'../effect/effect',
})
*3、小程序调用同级函数用
语法:this.函数名()
例子:this.count_down();
案例:
onLoad:
function (options) {
this.count_down();
},
count_down:
function () {
const that =
this;
setTimeout(
function () {
that.setData({ name:
"169.8" })
},
1000)
},
*数组选择属性名
chioce: [
{ interest:
'文化课', scale:
'180以上' },
{ interest:
'艺术', scale:
'0-50学员' },
{ interest:
'兴趣', scale:
'50-100学员' },
],
在html中渲染写
{{index? value.scale : value.interest}}