vue v-for 数据增加页面不刷新

javascript 复制代码
          <div style="float:left;border:1px solid red;height:100px;width:600px;">
            <el-form-item label="多语言配置" style="width:700px;" prop="validTanleHead">
              <el-input style="width: 180px" placeholder="请填写语言类型" v-model="lange_type" />
              <el-button class="filter-item" style="margin-left:0px;" type="primary" size="mini" @click="addLangeType()">添加语言类型</el-button>
              <br />
              <span></span>
              <div v-for="(item, index) in tableData">
                <!-- {{item}} -->
                {{index}} <el-button class="filter-item" style="margin-top:10px;" type="primary" size="mini" @click="addRow(index)">添加</el-button>
                <el-table :data="item" :key="index" style="width: 100%" border fit highlight-current-row>
                  <el-table-column prop="type" label="type" width="150">
                    <template slot-scope="scope">
                      <el-input class="tabletext" v-model="scope.row.type" size="mini" autosize />
                    </template>
                  </el-table-column>
                  <el-table-column prop="value" label="value" width="150">
                    <template slot-scope="scope">
                      <el-input class="tabletext" v-model="scope.row.value" size="mini" autosize />
                    </template>
                  </el-table-column>
                  <el-table-column prop="color" label="color" width="150">
                    <template slot-scope="scope">
                      <el-input class="tabletext" v-model="scope.row.color" size="mini" autosize />
                    </template>
                  </el-table-column>
                  <el-table-column prop="color" width="80">
                    <template slot-scope="scope">
                      <el-button size="mini" type="danger" @click="DeleteRow(scope.row,index)">删除</el-button>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </el-form-item>
          </div>

使用 Object.assign 可以解决

javascript 复制代码
addLangeType () {
      if (this.lange_type == "") {
        this.$message.error("请填写语言类型");
        return
      }
      //console.log("添加语言类型")
      // key就是数组的下标
      for (var key in this.tableData) {
        console.log(key);
        if (key == this.lange_type) {
          this.$message.error("语言类型已存在,请勿重复添加!");
          return
        }
        // console.log(this.tableData[key]);
      }

      var lange_type = this.lange_type
      var tempData = {
        [lange_type]: [{
          type: "",
          value: "",
          color: "",
        }]
      };
      this.tableData = Object.assign({}, this.tableData, tempData)
    },
相关推荐
JarvanMo14 分钟前
我的app被工信部下架了,现在想重新上架
前端
景早14 分钟前
小黑记账清单案例(axios,echarts,vue)
前端·vue.js·echarts
Mintopia14 分钟前
🌐 《GraphQL in Next.js 初体验》中文笔记
前端·后端·全栈
我穿棉裤了18 分钟前
使用css 给div添加四角线框
前端·css
Mintopia23 分钟前
🤖 通用人工智能(AGI)离 Web 应用还有多远?
前端·javascript·aigc
JianZhen✓42 分钟前
面试题名词解析一
前端
会跑的葫芦怪44 分钟前
Web3开发中的前端、后端与合约:角色定位与协作逻辑
前端·web3·区块链
江城开朗的豌豆1 小时前
TypeScript泛型:让类型也"通用"的魔法
前端·javascript
江城开朗的豌豆1 小时前
TypeScript函数:给JavaScript函数加上"类型安全带"
前端·javascript
凌览1 小时前
Node.js + Python 爬虫界的黄金搭档
前端·javascript·后端