vue v-for循环新增对象视图不更新

如题所示,在vm中利用对象数据和v-for进行列表渲染,但是在对象数据中新增一条键值为对象的数据之后,发现视图并未更新。查看官方文档也不知道该怎么写,求大牛赐教。代码如下:

    let shellObj = {};
    shellObj.name = name;
    shellObj.runCode = runCode;
    shellObj.storePath = storePath;
    if (file) {
      shellObj.filePath = file.path;
      fs.createReadStream(file.path)
         .pipe(fs.createWriteStream(userPath + '/Shell/' + file.name))
              .on('close', function () {
                  shellJson[name] = shellObj;
                  that.hideBlack();
              });
    } else {
      shellObj.filePath = '';
      shellJson[name] = shellObj;
      that.hideBlack();
    }
  shellJsonCopy[name] = shellObj;
  // shellJson = Object.assign(shellJson,shellJsonCopy);
  body.$set(body.$data.shellData,name, shellObj);
  // shellJson = Object.assign({}, shellJson, {
  //     [name]: shellObj
  // })
阅读 4.7k
1 个回答

试试 $forceUpdate() ,
vue 判断数据是否更新这部分 有点不准。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题