vuejs 獲取input的值

使用 refv-modelfunction(e)

<input type="text" value="調試 vuejs 2.0" ref="input1">
 <button   v-on:click="test1">測試</button>

<input type="text" v-model="input2">
<button  v-on:click="test2">測試</button>

// @input 輸入事件,實時監聽
<input type="text" @input="test3" /> 

methods: {
    test1: function () {
        console.log( this.$refs.input1.value ); 
    },

    test2: function () {
        console.log( this.input2 );
    },

    test3(e){
      //e.target 指向了dom元素
      console.log( e.target.value ); 
    }
}
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容