uni-app使用this.setData({})

1、设置数据 

在微信小程序中this.setData({}),可以设置一个或同时多个data数据,在uniapp中使用需要重写setData({})

<script>
export default { data() { return { sort_show: !1 scanReachBottom: !1, unitid: 123,
数据.................................................................. } }, methods: { setData: function(obj) { let that = this; let keys = []; let val, data; Object.keys(obj).forEach(function(key) { keys = key.split("."); val = obj[key]; data = that.$data; keys.forEach(function(key2, index) { if (index + 1 == keys.length) { that.$set(data, key2, val); } else { if (!data[key2]) { that.$set(data, key2, {}); } } data = data[key2]; }); }); }, active_nav:function(a) { var t = uni.$getAttr(a,"active_index"); this.active_index != t ? this.setData({ sort_show: !0, show_new: !1, active_index: t, brand_show: !1 }) : this.setData({ sort_show: !1, active_index: 0, show_new: !1 }); } } } </script>

  

  

 

posted @ 2022-09-27 20:55  游走的小鱼  阅读(3044)  评论(0编辑  收藏  举报