Ask for advice on what is the cause of the error in this vue v-for code and how to deal with it.

HTML structure

 <div class="config-item"> 
            <el-form-item label=""></el-form-item>
              <div v-for="item in exConfig " :key="item.exConfigKey" class="test-config-item">
              <el-form-item label="">{{item.exConfigName}}</el-form-item>
              <el-form-item label="" >
                <el-input v-model="item.testExConfig[item.exConfigKey]" @change="testChange(item)"></el-input>
              </el-form-item>
             <el-form-item label="">
                 <el-input v-model="item.releaseExConfig[item.exConfigKey]" @change="releaseChange(item)"></el-input>
              </el-form-item> 
             </div>
          </div>

js structure
is written in created

this.$nextTick(() => {
      this.$axios.post("/mock/dtp-admin/market/detail").then(res => {
        this.exConfig = res.data.exConfig;
        this.$axios.post("/mock/dtp-admin/hotel/detail").then(res => {
          let data1 = res.data.releaseExConfig;
          let data2 = res.data.testExConfig;
          this.exConfig = this.exConfig.map(item => ({
            ...item,
            releaseExConfig: { [item.exConfigKey]: data1[item.exConfigKey] },
            testExConfig: { [item.exConfigKey]: data2[item.exConfigKey] },
          }));
          console.log(this.exConfig[0].testExConfig.itemCode1);
        });
      });

    });

idea: take two interfaces in created to get the data, re-traverse and combine the data to get a new data structure, and then put it into html traversal and render it.
the structure after exConfig reorganization is as follows

exConfig:[{
        exConfigName:"1",
        exConfigKey:"itemCode1",
        data1:{
          itemCode1:"900001"
        },
        data2:{
          itemCode1:"900001"
        }
      },
      {
        exConfigName:"3",
        exConfigKey:"itemCode2",
        data1:{
          itemCode2:"900002"
        },
        data2:{
          itemCode2:"900002"
        }
        
      },
      {
        exConfigName:"4",
        exConfigKey:"itemCode3",
        data1:{
          itemCode3:"900003"
        },
        data2:{
          itemCode3:"900003"
        }
      },
      {
        exConfigName:"6",
        exConfigKey:"itemCode4",
        data1:{
          itemCode4:"900004"
        },
        data2:{
          itemCode4:"900004"
        }
      }]

an error is reported after the page is rendered, but the problem cannot be located

clipboard.png

clipboard.png
Don"t question whether there is a problem with itemCode1. This must exist

.
Mar.11,2022

has clearly told you that this attribute does not exist. Find out where to use itemCode1
console.log (this.exConfig [0] .testExfig.itemCode 1)
looks like this line, but you can't find testExConfig


in your data structure. The

error report makes it clear that there is no itemCode1 attribute.
clipboard.png

exConfigKeydata1data2itemCode11
clipboard.png


<el-form-item label="" >
  <el-input v-model="item.testExConfig ? item.testExConfig[item.exConfigKey] : ''" @change="testChange(item)"></el-input>
</el-form-item>
<el-form-item label="">
  <el-input v-model="item.releaseExConfig ? item.releaseExConfig[item.exConfigKey] : ''" @change="releaseChange(item)"></el-input>
</el-form-item> 

is the problem with your first piece of data:

{

exConfigName:"1",
exConfigKey:"itemCode1",
data1:{
  itemCode1:"900001"
},
data2:{
  itemCode1:"900001"
}

},


the request data that you write in nextTick must be executed after html rendering, so there is no testExConfig,testExConfig in item, so you can write a v-if and then turn the request data into true and then render html.
and writing nextTick in created seems to be no different from writing in mounted.

Menu