vue 新增的行数据保存后台,为什么总是在第一行内显示?


新增方法:

addFloor() {
      this.floors.push({
        title: '标题',
        comps: [],
        guid: Date.now(),
      });
    },

提交后台方法:

saveEdit() {
      const compIds = [];
      this.floors.forEach((floor) => {
        floor.comps.forEach((comp) => {
          compIds.push(comp.id);
          this.title = floor.title;
        });
      });
      createRowData([{ title: this.title, compAryIds: compIds }]).then((res) => {
        this.floors = res;
        console.log(this.floors);
        this.$message.success('保存成功');
      });
    },

但是保存后不论添加多少行,所有数据页面都显示在第一行:

而我想要的是这样:
[{第一行},{第二行}]
我错在哪里,大佬

阅读 1.5k
1 个回答
新手上路,请多包涵

不知道我有没有理解你的描述。
试试看下面这句:
const compAryIds = this.floors.map(floor => floor.comps.map(comp=> item.id))

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