怎么在vue中實現(xiàn)數(shù)據(jù)的雙向綁定-創(chuàng)新互聯(lián)

這篇文章給大家介紹怎么在vue中實現(xiàn)數(shù)據(jù)的雙向綁定,內容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。

成都創(chuàng)新互聯(lián)專注于東豐網(wǎng)站建設服務及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供東豐營銷型網(wǎng)站建設,東豐網(wǎng)站制作、東豐網(wǎng)頁設計、東豐網(wǎng)站官網(wǎng)定制、成都小程序開發(fā)服務,打造東豐網(wǎng)絡公司原創(chuàng)品牌,更為您提供東豐網(wǎng)站排名全網(wǎng)營銷落地服務。

具體如下:

<!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:將視圖中用戶操作的結果 綁定到指定的數(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>
    <h3>v-model.number</h3>
    <input type="text" v-model.number="n">
    <br>
    <input type="text" v-model.number="m">
    <br>
    <button @click="getNum">求和</button>
    <span>{{num}}</span>
    <hr>
    <h3>v-model.trim</h3>
    <h6>沒有過濾首尾空格時:</h6>
    <input type="text" v-model="myInput">
    <span>{{myInput.length}}</span>
    <h6>過濾首尾空格時:</h6>
    <input type="text" v-model.trim="myInput">
    <span>{{myInput.length}}</span>
    <h3>v-moddel.lazy</h3>
    <h6>input失去焦點時才會輸出myMsg</h6>
    <input type="text" v-model.lazy="myMsg">
    <span>{{myMsg}}</span>
  </div>
  <script>
    new Vue({
      el:"#container",
      data:{
        msg:"Hello VueJs",
        userAddress:"",
        n:0,
        m:0,
        num:0,
        myInput:0,
        myMsg:""
      },
      methods:{
        modifyMsg:function(){
          this.msg = "Hello Model"
        },
        getNum:function(){
          this.num = this.n+this.m;
        }
      }
    })
  </script>
 </body>
</html>

關于怎么在vue中實現(xiàn)數(shù)據(jù)的雙向綁定就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

文章標題:怎么在vue中實現(xiàn)數(shù)據(jù)的雙向綁定-創(chuàng)新互聯(lián)
文章起源:http://bm7419.com/article42/dsdeec.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內鏈、品牌網(wǎng)站制作、網(wǎng)站設計公司、關鍵詞優(yōu)化、全網(wǎng)營銷推廣、手機網(wǎng)站建設

廣告

聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

手機網(wǎng)站建設