詳解Vue.js之視圖和數據的雙向綁定(v-model)
更新時間:2017年06月23日 14:16:49 作者:Bwz_Learning
本篇文章主要介紹了Vue.js之視圖和數據的雙向綁定(v-model),使用v-model指令,使得視圖和數據實現雙向綁定,有興趣的可以了解一下
1、使用v-model指令,使得視圖和數據實現雙向綁定。v-model主要用在表單的input輸入框,完成視圖和數據的雙向綁定。
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、效果演示

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
vue組件中iview的modal組件爬坑問題之modal的顯示與否應該是使用v-show
這篇文章主要介紹了vue組件中iview的modal組件爬坑問題之modal的顯示與否應該是使用v-show,本文通過實例圖文相結合的形式給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-04-04
vue3中require報錯require is not defined問題及解決
這篇文章主要介紹了vue3中require報錯require is not defined問題及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-06-06
vue雙擊事件2.0事件監(jiān)聽(點擊-雙擊-鼠標事件)和事件修飾符操作
這篇文章主要介紹了vue雙擊事件2.0事件監(jiān)聽(點擊-雙擊-鼠標事件)和事件修飾符操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07
vue中提示$index is not defined錯誤的解決方式
這篇文章主要介紹了vue中提示$index is not defined錯誤的解決方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-09-09

