1***@qq.com
1***@qq.com
  • 发布:2019-02-19 11:49
  • 更新:2019-02-19 12:11
  • 阅读:2269

微信小程序如何动态绑定数据

分类:uni-app

我在h5调用了this.$set()方法是可以绑定数据并立刻渲染的,微信小程序为什么不能了?微信小程序该怎么写呢?

2019-02-19 11:49 负责人:无 分享
已邀请:
虫雪浓

虫雪浓 - 热爱生活,热爱编程

直接数据双向绑定就可以

  • 1***@qq.com (作者)

    我的不生效呀。你怎么写的?

    2019-02-19 11:58

  • 1***@qq.com (作者)

    应该对象的属性是不存在的,需要动态绑定的,所以只能用this.$set

    2019-02-19 11:59

  • 虫雪浓

    具体发代码,不要直接上效果图,没办法定位问题。

    2019-02-19 12:00

  • 1***@qq.com (作者)

    回复 虫雪浓:我写上去了

    2019-02-19 12:05

1***@qq.com

1***@qq.com (作者)

具体代码
js

data(){
return {
list1:{}
}
}
mounted() {
this.$set(this.list1,'a','ddds')
},

html

{{list1.a}}


  • 这样h5是显示的,但是微信小程序是不显示的
虫雪浓

虫雪浓 - 热爱生活,热爱编程

<template>  
    <view class="page">  
        {{list.a}}  
    </view>  
</template>

<script>  
    export default {  
        data() {  
            return {  
                list:{}  
            };  
        },  
        onLoad() {  
            this.list.a = '测试'  
        }  
    };  
</script>  

这样是没问题的。

该问题目前已经被锁定, 无法添加新回复