set v-model.trim
<input type="text" v-model.trim="brand">
<button @click="add">添加</button>
Print this.brand in the method to see if you get it
add(){
console.log(this.brand);
}
add button method code:
(because the object object is in the form of a key pair value, so it is a colon :)
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('请输入..')
}
},