1. 程式人生 > 程式設計 >Vue之表單事件資料繫結詳解

Vue之表單事件資料繫結詳解

在這裡插入圖片描述

<body>
    <div id="root">
        <form action="" @submit.prevent="demo">
            <label for="TW"> 姓名:</label>
            <input type="text" id="TW" v-model.trim="userInfo.account"><br><br> 密碼:
            <input type="passwww.cppcns.comword" id="pa" v-model="userInfo.password"><br><br> 年齡:
            <input type="number" v-model.number="userInfo.age"> <br><br> 性別: <input type="radio" name="sex" value="male" v-model="userInfo.sex">男
  www.cppcns.com
<input type="radio" name="sex" v-model="userInfo.sex" value="female">女<br><br> 愛好: 所屬校區: <select v-model="userInfo.city"> <option value="school">請選擇校區</option> <option value="beijing">北京</option> <option value="shanghai">上海</option> <option value="shenzhen">深圳</option> </select> <br><br> <input type="checkbox" v-model="userInfo.hobby" value="study"> 學習 <input type="checkbox" v-model="userInfo.hobby" value="sing"> 唱歌 <input type="checkbox" v-model="userInfo.hobby" value="dance"> 跳舞 <input type="checkbox" v-model="userInfo.hobby" value="game"> 王者<br><br> 其他資訊: <textarea name="" v-model.lazy="userInfo.other"></textarea><br><br> <input type="checkbox" v-model="userInfo.agree"> 閱讀並接受 <a href="#">《使用者協議》</a><button>提交</button> </form> </div> <script> .config.productionTip = false; new Vue({ el: '#root',data: { userInfo: { account: '',password: '',age: '',sex: 'female',city: 'beijing',hobby: [],other: '',agree: '',} www.cppcns.com
},methods: { demo() { console.log(ON.stringify(this.userInfo)); } } }) </script> </body>

總結

本篇文章就到這裡了,希望能夠給你帶來幫助,也希望您能夠多多關注我們的更多內容!