wepy ——$apply

1、说明

在异步函数中更新数据的时候,必须手动调用 $apply 方法。

 

2、代码和效果

// html
<button type="primary" plain="true">{{fruit}}</button>

// js
data = {
  fruit: ‘苹果‘
}
onShow(){
  setTimeout(() => {
    this.fruit = "橘子";
    console.log(this.fruit);   // 橘子
    this.$apply();
  },1500)
}

 

wepy ——$apply

 

如果不加 this.$apply(); 这一句,即使 fruit 已改变,但是依赖 fruit 这个数据所渲染的视图将不会更新。

wepy ——$apply

上一篇:springboot配置文件 application.yml注意事项(Failed to load property source from location 'classpath:/applica)


下一篇:[LINQ2Dapper]最完整Dapper To Linq框架(六)---多表联合与匿名类型返回