How to get the value of the input input in vue and add it to the form

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

Guess you like

Origin blog.csdn.net/weixin_57607714/article/details/123406499