1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| <body> <div id="demo"> <form action="/xxx" @submit.prevent="handleSubmit"> <span>用户名:</span> <input type="text" v-model="username"><br>
<span>密码:</span> <input type="password" v-model="pwd"><br>
<span>性别:</span> <input type="radio" id="female" value="女" v-model="gender"> <label for="female">女</label> <input type="radio" id="male" value="男" v-model="gender"> <label for="male">男</label><br>
<span>爱好:</span> <input type="checkbox" id="basketball" value="bk" v-model="hobbit"> <label for="basketball">篮球</label> <input type="checkbox" id="football" value="ft" v-model="hobbit"> <label for="football">足球</label> <input type="checkbox" id="pingpang" value="pp" v-model="hobbit"> <label for="pingpang">乒乓</label><br>
<span>城市:</span> <select v-model="cityId"> <option value="">未选择</option> <option :value="city.id" v-for="(city, index) in allCitys" :key="index">{{city.name}}</option> </select><br> <span>介绍:</span> <textarea rows="10" v-model="description"></textarea><br><br>
<input type="submit" value="注册"> </form> </div>
<script type="text/javascript" src="../js/vue.js"></script> <script type="text/javascript"> new Vue({ el: "#demo", data: { username: '', pwd: '', gender: '女', hobbit: ['bk', 'ft'], allCitys: [{ id: 1, name: '北京' }, { id: 2, name: '上海' }, { id: 3, name: '深圳' }], cityId: '3', description: '' }, methods: { handleSubmit() { console.log(this.username, this.pwd, this.gender, this.hobbit, this.cityId, this.description); } } }) </script> </body>
|