欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

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

最编程 2024-03-07 21:40:37
...

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>

  

原文地址:https://www.cnblogs.com/891288436xiaoyu/p/16735979.html