欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

Vue框架之鍵盤事件、健值修飾符、雙向數(shù)據(jù)綁定

一、鍵盤事件,當(dāng)按鍵盤時,在控制臺輸出提示

清原網(wǎng)站制作公司哪家好,找成都創(chuàng)新互聯(lián)!從網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、自適應(yīng)網(wǎng)站建設(shè)等網(wǎng)站項目制作,到程序開發(fā),運營維護。成都創(chuàng)新互聯(lián)從2013年成立到現(xiàn)在10年的時間,我們擁有了豐富的建站經(jīng)驗和運維經(jīng)驗,來保證我們的工作的順利進行。專注于網(wǎng)站建設(shè)就選成都創(chuàng)新互聯(lián)

Vue 框架之鍵盤事件、健值修飾符、雙向數(shù)據(jù)綁定

html 源碼:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>VueLearn-cnblogs/xpwi</title>
    <!--引入自定義的樣式-->
    <link rel="stylesheet" href="css/style.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" />
    <!--引入 vue 核心 js-->
    <script type="text/javascript" src="js/vue.js" ></script>
    
  </head>
  <body>
    
    <!--vue-app 是根容器,定義一個 id,然后在 js 里操作-->
    <div id="vue-app">
      
      <!--name 具體的值是在 js 中定義的-->
      <h3> 鍵盤 Events </h3>
      <label>姓名:</label>
      <input type="text" v-on:keyup="logName" />
      <label>年齡:</label>
      <input type="text" v-on:keyup="logAge" />
      
    
    </div>
    
    <!--引入自己的 js,注意必須寫在 body 標簽里最后,因為必須先加載你的整個 HTML DOM,才回去執(zhí)行 vue 實例-->
    <script type="text/javascript" src="js/appEvent.js" ></script>
  </body>
</html>

js 源碼:

//實例化 vue 對象
new Vue({
  //注意代碼格式
  //el:element 需要獲取的元素,一定是 html 中的根容器元素
  el:"#vue-app",
  data:{
  },
  methods:{
    logName: function(){
      console.log("你這正在輸入名字!");
      
    },
    logAge: function(){
      console.log("你這正在輸入年齡!");
      
    }
  }
});

上面代碼是當(dāng)用戶點擊輸入框后,只要按下鍵盤就會在控制臺打印一次提示,實際應(yīng)用的并不多,下面介紹當(dāng)用戶按下回車鍵時,才觸發(fā)

二、健值修飾符

下面在時間后面加上:.enter
就可以實現(xiàn)只監(jiān)聽 enter 鍵,就可以實現(xiàn),當(dāng)用戶在輸入完成,按下回車鍵時,觸發(fā)我們自定義的事件
<input type="text" v-on:keyup.enter="logName" />

三、雙向數(shù)據(jù)綁定 input,selecet,textarea

適用:input,selecet,textarea 三種標簽

js 文件種拿到 html 文件種輸入的數(shù)據(jù),然后 html 中拿到 js 文件中的數(shù)據(jù)

Vue 框架之鍵盤事件、健值修飾符、雙向數(shù)據(jù)綁定

源代碼 html 文件:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>VueLearn-cnblogs/xpwi</title>
    <!--引入自定義的樣式-->
    <link rel="stylesheet" href="css/style.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" />
    <!--引入 vue 核心 js-->
    <script type="text/javascript" src="js/vue.js" ></script>
    
  </head>
  <body>
    
    <!--vue-app 是根容器,定義一個 id,然后在 js 里操作-->
    <div id="vue-app">
      
      <!--name 具體的值是在 js 中定義的-->
      <h3> 鍵盤 Events </h3>
      <label>姓名:</label>
      <!--加一個 ref 用來在 js 文件中拿到 input 標簽中輸入的內(nèi)容-->
      <input ref="userName" type="text" />
      <label>年齡:</label>
      <input ref="userAge" type="text" v-on:keyup.enter="notice" />
      
      <hr />
      <span>已確認信息:</span>
      <br />
      姓名:{{name}}<br />
      年齡:{{age}}
    
    </div>
    
    <!--引入自己的 js,注意必須寫在 body 標簽里最后,因為必須先加載你的整個 HTML DOM,才回去執(zhí)行 vue 實例-->
    <script type="text/javascript" src="js/appEvent.js" ></script>
  </body>
</html>

源代碼 js 文件:

//實例化 vue 對象
new Vue({
  //注意代碼格式
  
  //el:element 需要獲取的元素,一定是 html 中的根容器元素
  el:"#vue-app",
  data:{
    name : "",
    age : ""
  },
  methods:{
  
    notice: function(){
      //console.log("你這正在輸入年齡!");
      //this.name 是 js 文件上面定義的一個 name 變量
      this.name = this.$refs.userName.value;
      this.age = this.$refs.userAge.value;
      alert("姓名:" + this.name + " 年齡:" + this.age);
    }
  }
});

四、雙向數(shù)據(jù)綁定 input,selecet,textarea (二)

上面數(shù)據(jù)綁定是在按下 輸入回車鍵的時候,來回的同步數(shù)據(jù),下面介紹另一種方式,實現(xiàn)雙向數(shù)據(jù)綁定

Vue 框架之鍵盤事件、健值修飾符、雙向數(shù)據(jù)綁定

雙向數(shù)據(jù)綁定第二種方法:

 源代碼 html 文件:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>VueLearn-cnblogs/xpwi</title>
    <!--引入自定義的樣式-->
    <link rel="stylesheet" href="css/style.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" />
    <!--引入 vue 核心 js-->
    <script type="text/javascript" src="js/vue.js" ></script>
    
  </head>
  <body>
    
    <!--vue-app 是根容器,定義一個 id,然后在 js 里操作-->
    <div id="vue-app">
      
      <!--name 具體的值是在 js 中定義的-->
      <h3> 鍵盤 Events </h3>
      <label>姓名:</label>
      <!--加一個 ref 用來在 js 文件中拿到 input 標簽中輸入的內(nèi)容-->
      <input ref="userName" type="text" v-model="name" />
      <label>年齡:</label>
      <input ref="userAge" type="text" v-model="age"/>
      
      <hr />
      <span>同步數(shù)據(jù):</span>
      <br />
      姓名:{{name}}<br />
      年齡:{{age}}
    
    </div>
    
    <!--引入自己的 js,注意必須寫在 body 標簽里最后,因為必須先加載你的整個 HTML DOM,才回去執(zhí)行 vue 實例-->
    <script type="text/javascript" src="js/appEvent.js" ></script>
  </body>
</html>

源代碼 js 文件:

//實例化 vue 對象
new Vue({
  //注意代碼格式
  
  //el:element 需要獲取的元素,一定是 html 中的根容器元素
  el:"#vue-app",
  data:{
    name : "",
    age : ""
  },
  methods:{
  
    notice: function(){
      //console.log("你這正在輸入年齡!");
      //this.name 是 js 文件上面定義的一個 name 變量
      this.name = this.$refs.userName.value;
      this.age = this.$refs.userAge.value;
      alert("姓名:" + this.name + " 年齡:" + this.age);
    }
  }
});

總結(jié)

以上所述是小編給大家介紹的Vue 框架之鍵盤事件、健值修飾符、雙向數(shù)據(jù)綁定,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對創(chuàng)新互聯(lián)網(wǎng)站的支持!

名稱欄目:Vue框架之鍵盤事件、健值修飾符、雙向數(shù)據(jù)綁定
網(wǎng)頁地址:http://chinadenli.net/article14/ggjpge.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)企業(yè)建站搜索引擎優(yōu)化標簽優(yōu)化靜態(tài)網(wǎng)站網(wǎng)站導(dǎo)航

廣告

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

外貿(mào)網(wǎng)站建設(shè)