vue動態(tài)輸入框

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("必須保留一個");
                }
            },
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容