设置v-model.trim 修饰符消除空格

 <input type="text" v-model.trim="brand">
 <button @click="add">添加</button>

新增按钮方法代码:

(因为object对象是键对值的形式  所以是冒号:) 

    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('请输入..')
      }
    },

Logo

前往低代码交流专区

更多推荐