v-model.trimを設定します
<input type="text" v-model.trim="brand">
<button @click="add">添加</button>
メソッドにthis.brandを印刷して、取得できるかどうかを確認します
add(){
console.log(this.brand);
}
ボタンメソッドコードを追加します。
(オブジェクトオブジェクトはキーペア値の形式であるため、コロンです:)
add() {
console.log(this.brand);
if (this.brand != "") { //如果输入的值不为空
let obj = {
id: this.nextId,
name: this.brand,
};
this.list.push(obj);
this.brand = "";
this.nextId++;
} else {
alert('请输入..')
}
},