v-mode
可以应用于输入框、单选框、多选框。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<body>
<div id="app">
姓名:<input v-model="name"><br />
单身:<input type="checkbox" v-model="isSingle"><br />
爱好:
足球:<input type="checkbox" value="football" v-model="hobby">
篮球:<input type="checkbox" value="basketball" v-model="hobby"><br />
性别:
男:<input type="radio" value="male" v-model="gender">
女:<input type="radio" value="female" v-model="gender"><br />
所在城市:
<select v-model="cityId">
<option value="101">北京</option>
<option value="102">上海</option>
<option value="103">广州</option>
<option value="104">深圳</option>
</select>
</div>
<script>
const app = new Vue({
el: '#app',
data: {
name: '张三',
hobby: ['football', 'basketball'],
isSingle: true,
gender: 'male',
cityId: 103
}
})
</script>
</body>
</html>