本文實例講述了vue實現(xiàn)的雙向數(shù)據(jù)綁定操作。分享給大家供大家參考,具體如下:
<!doctype html> <html> <head> <meta charset="UTF-8"> <title>經(jīng)典的雙向數(shù)據(jù)綁定</title> <script src="https://cdn.bootcss.com/vue/2.0.1/vue.min.js"></script> </head> <body> <div id="container"> <button @click="modifyMsg">修改msg</button> <!-- 方向1:將定義好的數(shù)據(jù)綁定到試圖 實現(xiàn)方式:雙花括號 常見指令:v-for v-if v-show …… --> <!-- 方向2:將視圖中用戶操作的結(jié)果 綁定到指定的數(shù)據(jù) (多數(shù)指表單控件 input/textarea/select) 實現(xiàn)方式: v-model --> <p>{{msg}}</p> <input type="text" v-model="userAddress"> <p>{{"用戶修改的數(shù)據(jù):"+userAddress}}</p> <hr> <h2>v-model.number</h2> <input type="text" v-model.number="n"> <br> <input type="text" v-model.number="m"> <br> <button @click="getNum">求和</button> <span>{{num}}</span> <hr> <h2>v-model.trim</h2> <h5>沒有過濾首尾空格時:</h5> <input type="text" v-model="myInput"> <span>{{myInput.length}}</span> <h5>過濾首尾空格時:</h5> <input type="text" v-model.trim="myInput"> <span>{{myInput.length}}</span> <h2>v-moddel.lazy</h2> <h5>input失去焦點時才會
使用在線HTML/CSS/JavaScript代碼運行工具:http://tools.jb51.net/code/HtmlJsRun測試,可得到如下運行效果
感興趣的朋友可以測試一下看看運行效果。
希望本文所述對大家vue.js程序設(shè)計有所幫助。
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com