博客
关于我
vue页面数组做数据置顶
阅读量:529 次
发布时间:2019-03-08

本文共 953 字,大约阅读时间需要 3 分钟。

//置顶    async stickHonor(index) {    //index为数据当前下标      let obj = this.honorList[index];      const id = obj.id;      obj.isStick = 1;      console.log(id);      const isStick = 1;   //置顶状态      const res = await stickStudentHonors({ id,isStick });  //调用接口改变数据状态      //删除之前的位置的数据      this.honorList.splice(index, 1);      //在数组下标为0插入数据,每次置顶数据都是在最前面      this.honorList.splice(0, 0, obj);    },    //取消置顶    async unstickHonor(index) {   //index为数据当前下标      let sum = 0;      for (let data of this.honorList) {        if (data.isStick == 1) {          sum++;        }      }      let obj = this.honorList[index];      const id = obj.id;      const isStick = 0;    //为不置顶      const res = await stickStudentHonors({ id,isStick });    //调用接口改变数据的状态      obj.isStick = 0;      //删除之前的位置的数据      this.honorList.splice(index, 1);      //置顶数据下面插入数据,因为sum把之前自己置顶的也算进去,所以sum-1      this.honorList.splice(sum-1, 0, obj);    }

   因为splice()方法为vue数组的响应式方法,所以会自动刷新数据

转载地址:http://ffviz.baihongyu.com/

你可能感兴趣的文章
mysql 编译安装 window篇
查看>>
mysql 网络目录_联机目录数据库
查看>>
MySQL 聚簇索引&&二级索引&&辅助索引
查看>>
Mysql 脏页 脏读 脏数据
查看>>
mysql 自增id和UUID做主键性能分析,及最优方案
查看>>
Mysql 自定义函数
查看>>
mysql 行转列 列转行
查看>>
Mysql 表分区
查看>>
mysql 表的操作
查看>>
mysql 视图,视图更新删除
查看>>
MySQL 触发器
查看>>
mysql 让所有IP访问数据库
查看>>
mysql 记录的增删改查
查看>>
MySQL 设置数据库的隔离级别
查看>>
MySQL 证明为什么用limit时,offset很大会影响性能
查看>>
Mysql 语句操作索引SQL语句
查看>>
MySQL 误操作后数据恢复(update,delete忘加where条件)
查看>>
MySQL 调优/优化的 101 个建议!
查看>>
mysql 转义字符用法_MySql 转义字符的使用说明
查看>>
mysql 输入密码秒退
查看>>