vue dynamically adds variables to data
My business is to dynamically assign values to v-model, but you have to change it, so you can't do one-to-one, then you have to dynamically create variables
First you have to know what your data structure looks like, and then you use an array to dynamically create variables based on the structure of your data.
Then use the empty array you created to correspond to the v-model assignment one by one
- js:
for (var i =0;i< _this.;i++) { _this.([]); for (var k = 0;k<_this.[i].;k++) { _this.timeSet[i].push({stopTime:'',measureText:''}); } }
- data:
timeSet : [];
- html:
<div class="module"> <div class="question-group" v-for="(item,index) in " :key="index"> <p class="group-title">{{}}</p> <div class="group-content" v-for="(list,idx) in " :key="idx"> <div class="question"> <div class="question-type">all</div> <p class="question-title">{{}}</p> <div class="question-sub"> <p class="title">Voucher details</p> <textarea class="input-show" placeholder="Please enter the measures" v-model="timeSet[index][idx].measureText"></textarea> </div> <div class="question-options form-item-group"> <div class="module-wrapper half"> <!-- Time selection(With title) --> <div class="form-item with-label"> <p class="label">Mission end time<span class="required">*</span></p> <div class="module"> <flat-pickr :config="pickrConfig" placeholder="Please select the end time" v-model="timeSet[index][idx].stopTime"></flat-pickr> </div> </div> </div> </div> </div> </div> </div> </div>
vue dynamically adds suffixes to variables in data
For example, show1, show2, show3, and show4 declared in data, it is showX when there is a scene.
A variable is needed to assign values of 1, 2, 3, 4...
let index = 1/2/3/4 this[`show${index}`]
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.