学小程序踩过的坑

 *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}}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值