Blogger Information
Blog 250
fans 3
comment 0
visits 321390
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Vue自学: v-model的使用(双向绑定input标签)
梁凯达的博客
Original
1464 people have browsed it

<!DOCTYPE html>

<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.12"></script>
<title>Vue自学: v-model的使用(双向绑定input标签)</title>
</head>
<body>
<!-- v-model实现双向绑定:方法1 -->
<div id="app">
<input type="text" name="" v-model="message"/>
{{message}}
</div>
<!-- v-model实现双向绑定:方法2:原生方法实现 -->
<div id="app1">
<input type="text" v-bind:value="message" v-on:input="getValue"/>
{{message}}
</div>
<!-- v-model实现双向绑定:方法3:表达式实现 -->
<div id="app2">
<input type="text" v-bind:value="message" v-on:input="message = $event.target.value"/>
{{message}}
</div>
</body>
<script type="text/javascript">
const app = new Vue({
el:’#app’,
data:{
message:’this is a input’
},
methods:{

}
})
const app1 = new Vue({
el:’#app1’,
data:{
message:’this is a input’
},
methods:{
getValue($event){
this.message = $event.target.value
}
}
})
const app2 = new Vue({
el:’#app2’,
data:{
message:’this is a input’
},
methods:{

}
})
</script>
</html>

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post