詳解Vue.js之視圖和數(shù)據(jù)的雙向綁定(v-model)
1、使用v-model指令,使得視圖和數(shù)據(jù)實(shí)現(xiàn)雙向綁定。v-model主要用在表單的input輸入框,完成視圖和數(shù)據(jù)的雙向綁定。
2、JavaScript代碼
<script type="text/javascript" src="../js/vue-1.0.21.js"></script>
<script type="text/javascript">
window.onload = function() {
vm = new Vue({
el: '#app',
data: {
message: 'Hello World',
}
});
}
</script>
3、Html的頁面代碼
<div id="app" class="container">
<input type="text" v-model='message'/> <input type="text" v-model='message'/>
<br />
{{message}}
</div>
4、完整的代碼
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="../css/bootstrap.min.css" rel="external nofollow" />
<style type="text/css">
.container{
margin-top: 20px;
}
</style>
<script type="text/javascript" src="../js/vue-1.0.21.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript">
$().ready(function() {
var vm = new Vue({
el: '#app',
data: {
message: "Hello World ! "
}
});
});
</script>
</head>
<body>
<div id="app" class="container">
<input type="text" v-model='message'/> <input type="text" v-model='message'/>
<br />
{{message}}
</div>
</body>
</html>
5、效果演示

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue.js與element-ui實(shí)現(xiàn)菜單樹形結(jié)構(gòu)的解決方法
本文通過實(shí)例給大家介紹了vue.js與element-ui實(shí)現(xiàn)菜單樹形結(jié)構(gòu),非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2018-04-04
vue項(xiàng)目退出登錄清除store數(shù)據(jù)的三種方法
Vue3圖片上傳報(bào)錯(cuò):Required?part?‘file‘?is?not?present.的原因及解決方法
vue使用v-if v-show頁面閃爍,div閃現(xiàn)的解決方法
vue-cli打包后本地運(yùn)行dist文件中的index.html操作

