博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
vue.js遇到的问题-数组数据改变,页面不能实时显示
阅读量:4097 次
发布时间:2019-05-25

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

对于这种表单,有删除,上移,下移等操作

在上移下移时会遇到一个问题,

 

由于 JavaScript 的限制,Vue 不能检测以下变动的数组:

  1. 当你利用索引直接设置一个项时,例如:vm.items[indexOfItem] = newValue
  2. 当你修改数组的长度时,例如:vm.items.length = newLength

因此,我的移动操作代码是,以下移为例

 

// 向下移动  resultStepsList是列表数据downStepsIndex:function(item,index){    var smallItem = this.resultStepsList[index];    var largeItem = this.resultStepsList[index+1];    this.resultStepsList.$set(index,largeItem);    this.resultStepsList.$set(index+1,smallItem);},

利用索引直接设置一个项,Vue 不能检测以下变动的数组。导致页面不能实时显示我上移和下移后的结果

用“ 实例方法”就能解决这个问题

 

高版本的用法:this.$set(this.resultStepsList,index,largeItem);this.$set(this.resultStepsList,index+1,smallItem);

 

你可能感兴趣的文章
ubuntu 下编译PHP5.5.7问题:configure: error: freetype.h not found.
查看>>
PHP编译configure时常见错误 debian centos
查看>>
configure: error: Please reinstall the BZip2 distribution
查看>>
OpenCV gpu模块样例注释:video_reader.cpp
查看>>
【增强学习在无人驾驶中的应用】
查看>>
《python+opencv实践》四、图像特征提取与描述——29理解图像特征
查看>>
《python+opencv实践》四、图像特征提取与描述——30Harris 角点检测
查看>>
《python+opencv实践》四、图像特征提取与描述——31 Shi-Tomasi 角点检测& 适合于跟踪的图像特征
查看>>
OpenCV meanshift目标跟踪总结
查看>>
人工神经网络——神经元模型介绍
查看>>
人工神经网络——感知器介绍
查看>>
人工神经网络——反向传播算法(BackPropagation)
查看>>
进程的地址空间概述
查看>>
Windows 窗口底层原理
查看>>
一种函数指针的运用
查看>>
Win32程序之进程的原理
查看>>
C++虚函数原理
查看>>
MySQL的索引
查看>>
今天,Python信息量很大!
查看>>
Flash 已死,Deno 当立?
查看>>