首页 > 其他分享 >关于vue在列表展示数据的时候,更改其中一项,列表没有跟着实时变动的问题

关于vue在列表展示数据的时候,更改其中一项,列表没有跟着实时变动的问题

时间:2023-07-09 16:45:11浏览次数:32  
标签:index vue thatthis dataList res 更改 列表 indexData 页面

背景:

使用低代码自动生成的Vue前端大致页面,然后自定义其中的业务

涉及的页面:

 遇到的问题:

点击添加后,直接变更添加行的状态(输入框不可编辑、状态变为已激活)

涉及代码:

    addRecordAndApply(index) {
      let thatthis = this;
      let indexData = this.dataList[index];
      indexData.enterpris = queryModel.enterpris
      // indexData.id = '111111'

      //1更新完数据后,页面未渲染
      //  this.dataList.splice(index, 1,indexData)

       //2更新完数据后,页面未渲染
      // this.$set(this.dataList,index,indexData)

       //3深拷贝 更新完数据后,页面渲染
      // this.$set(this.dataList,index,_.cloneDeep(indexData))
      // // thatthis.$forceUpdate()

      // return;
      dibootApi.post(`${thatthis.baseApi}/`, indexData).then(res => {
        console.log(res)
        if (res.ok) {
          //4新内存数据 更新完数据后,页面渲染
          thatthis.$set(thatthis.dataList,index,res.data)
          thatthis.$message.success('已添加')

        } else {
          thatthis.$message.error(res.msg)
        }

      }).catch((e) => {
        thatthis.$message.error(e.message)
      })


    },

如上所示,在列表中更新数据,如果不是深拷贝或者新建的数据,不会触发Vue的页面渲染

 

标签:index,vue,thatthis,dataList,res,更改,列表,indexData,页面
From: https://www.cnblogs.com/timseng/p/17538932.html

相关文章

  • vue-day10--键盘事件
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"/><metaname="viewport"content="width=device-width,initial-scale=1.0"/><title>Document</title><script......
  • 前端Vue仿京东淘宝我的优惠券列表组件 用于电商我的优惠券列表页面
    随着技术的发展,开发的复杂度也越来越高,传统开发方式将一个系统做成了整块应用,经常出现的情况就是一个小小的改动或者一个小功能的增加可能会引起整体逻辑的修改,造成牵一发而动全身。通过组件化开发,可以有效实现单独开发,单独维护,而且他们之间可以随意的进行组合。大大提升开发效率......
  • vue-day9--事件修饰符
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"/><metaname="viewport"content="width=device-width,initial-scale=1.0"/><title>Document</title><script......
  • Vue之beforeRouteEnter的使用
    beforeRouteEnter用于路由跳转后进入新的页面进行操作,由于<scriptsetup>里面没有内置beforeRouteEnter的语法,所以需要另外写一个<script>标签。下面代码是beforeRouteEnter的使用示例,从from可以获得跳转页面前的路由信息。<script>import{defineComponent}from"vue";c......
  • centos8的root密码更改
    centos8的root密码更改此界面按e在linux行末尾加入参数rd.break按ctrl+s保存。ctrl+x启动输入mount-orw,remount/sysroot重新挂载sysroot并赋予rw权限输入chroot/sysroot把sysroot修改为/目录通过passwdroot或者echo1|passwd--stdinroottouch/.autorelabel重置SEli......
  • element table列表根据数据设置背景色
    效果页面代码通过:cell-class-name动态绑定类名<el-table:data="tableData"style="width:100%":cell-class-name="myclass"><el-table-columnprop="date"label="日期"width="180"></el-ta......
  • jQuery 学习列表
    jQuery  学习列表 1、EventsPageLoad$.ready(fn() )SpecifyafunctiontoexecutewhentheDOMisfullyloaded. 2、SelectorsBasics#idSelectsasingleelementwiththegivenidattribute.eleme......
  • 列表生成器
    #自动生成123l=list(range(1,4))print(l)#求1*12*23*3l2=[]forxinrange(1,4):l2.append(x*x)print(l2)#简化print([x*xforxinrange(1,4)])#求x*x中的偶数print([x*xforxinrange(1,4)ifx%2==0])#求双层循环print([m+nfor......
  • Vue详解设置路由导航的两种方法<router-link to=“”>和router.push(...)
    1.<router-linkto="">to里的值可以是一个字符串,也可以是一个描述地址的对象。//字符串<router-linkto="apple">toapple</router-link>//对象<router-link:to="{path:'apple'}">toapple</router-link>//命名路由&l......
  • vue store中存储的数据,走谷歌浏览器 那里可以看到
    在Vue的应用程序中,存储在Vuex(也称为VueStore)中的数据是在浏览器的开发者工具中查看的。对于谷歌浏览器(Chrome),你可以按照以下步骤在开发者工具中查看Vuex中的数据:在你的Vue应用程序中打开谷歌浏览器并加载页面。右键单击页面上的任何位置,并选择"检查"或使用快捷键F1......