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
推荐阅读
-
使用 PlantUML 绘制活动图和泳道图
-
Translation | 如何在对类别不平衡数据使用超采样或欠采样后正确进行交叉验证?
-
使用 Docker 和 Homeassistant,让家庭用电更轻松,帮您省电省钱
-
Ubuntu 进程管理器可查看当前 GPU 的使用情况以及哪个用户正在使用它
-
JEECG 技术文档]JEECG 接口权限开发和配置使用指南
-
SQLite 子查询示例 - 在 SELECT 语句中使用子查询
-
详细解释如何在 Linux 中使用 cron 计划任务
-
使用 Node.js 获取用户的操作系统和版本号
-
使用 ganache 实现 Web3js 与区块链交互的步骤及问题解决方案:未找到命令 "express "等。
-
java:使用 EasyExcel (a) 读取 excel