本文實(shí)例講述了vue實(shí)現(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ù)綁定到試圖 實(shí)現(xiàn)方式:雙花括號(hào) 常見(jiàn)指令:v-for v-if v-show …… --> <!-- 方向2:將視圖中用戶操作的結(jié)果 綁定到指定的數(shù)據(jù) (多數(shù)指表單控件 input/textarea/select) 實(shí)現(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>沒(méi)有過(guò)濾首尾空格時(shí):</h5> <input type="text" v-model="myInput"> <span>{{myInput.length}}</span> <h5>過(guò)濾首尾空格時(shí):</h5> <input type="text" v-model.trim="myInput"> <span>{{myInput.length}}</span> <h2>v-moddel.lazy</h2> <h5>input失去焦點(diǎn)時(shí)才會(huì)
使用在線HTML/CSS/JavaScript代碼運(yùn)行工具:http://tools.jb51.net/code/HtmlJsRun測(cè)試,可得到如下運(yùn)行效果
感興趣的朋友可以測(cè)試一下看看運(yùn)行效果。
希望本文所述對(duì)大家vue.js程序設(shè)計(jì)有所幫助。
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com