首页 > 移动平台 > 详细

wepy ——$apply

时间:2019-11-14 19:17:23      阅读:97      评论:0      收藏:0      [点我收藏+]

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

 

技术分享图片

 

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

wepy ——$apply

原文:https://www.cnblogs.com/xulinjun/p/11859155.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!