vue動態(tài)輸入框
//頁面例子部分
<tr v-for="(item,index) in 你的數(shù)組">
<td>規(guī)格:{{index+1}}</td>
<td>
<input placeholder="請輸入規(guī)格參數(shù)" v-model="item.字段">
<input placeholder="請輸入價格" v-model="item.字段">
<input placeholder="請輸入庫存" v-model="item.字段">
<button type="button" @click="downObj(item)">—</button>
<button v-if="index==你的數(shù)組.length-1" type="button" @click="addObj()">+</button>
</td>
</tr>
//vue的 methods:內(nèi)容加入兩個方法
/**
* 添加一個
*/
addObj: function () {
//加一個
this.你的數(shù)組.push({})
},
/**
* 減少一個
*/
downObj: function (item) {
//長度是否大于1
if (this.你的數(shù)組.length > 1) {
//獲取下標減1
let indexOf = this.你的數(shù)組.indexOf(item);
this.你的數(shù)組.splice(indexOf, 1);
} else {
alert("必須保留一個");
}
},