欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue基礎(chǔ)之事件v-onclick="函數(shù)"用法示例

 更新時(shí)間:2019年03月11日 08:42:17   作者:白楊-M  
這篇文章主要介紹了vue基礎(chǔ)之事件v-onclick="函數(shù)"用法,結(jié)合實(shí)例形式分析了vue.js事件v-on:click="函數(shù)"的data數(shù)據(jù)添加、點(diǎn)擊響應(yīng)、以及留言本功能相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了vue基礎(chǔ)之事件v-onclick=函數(shù)用法。分享給大家供大家參考,具體如下:

v-on:click/mouseout/mouseover/dblclick/mousedown.....

事件:

v-on:click="函數(shù)"
v-on:click/mouseout/mouseover/dblclick/mousedown.....

new Vue({
  el:'#box',
  data:{ //數(shù)據(jù)
    arr:['apple','banana','orange','pear'],
    json:{a:'apple',b:'banana',c:'orange'}
  },
  methods:{
    show:function(){  //方法,這里是show,不能用alert
      alert(1);
    }
  }
});

實(shí)例:為data添加數(shù)據(jù)

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>www.dbjr.com.cn 為data添加數(shù)據(jù)</title>
  <style>
  </style>
  <script src="https://cdn.bootcss.com/vue/2.4.4/vue.min.js"></script>
  <script>
    window.onload=function(){
      new Vue({
        el:'#box',
        data:{ //數(shù)據(jù)
          arr:['apple','banana','orange','pear'],
          json:{a:'apple',b:'banana',c:'orange'}
        },
        methods:{
          add:function(){
            this.arr.push('tomato');//this指代new Vue(),也是data
          }
        }
      });
    };
  </script>
</head>
<body>
  <div id="box">
    <input type="button" value="按鈕" v-on:dblclick="add()">
    <br>
    <ul>
      <li v-for="value in arr">
        {{value}}
      </li>
    </ul>
  </div>
</body>
</html>

運(yùn)行效果:

實(shí)例:點(diǎn)擊按鈕,div顯示/消失,切換。v-show="a"

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>www.dbjr.com.cn 點(diǎn)擊按鈕,div顯示/消失,切換。v-show="a"</title>
  <style>
  </style>
  <script src="https://cdn.bootcss.com/vue/2.4.4/vue.min.js"></script>
  <script>
    window.onload=function(){
      new Vue({
        el:'#box',
        data:{ //數(shù)據(jù)
          a:true
        },
        methods:{
          adjust:function(){
            console.log(this.a);
            if(this.a == true){
              this.a = false;
            }else{
              this.a = true;
            }
          }
        }
      });
    };
  </script>
</head>
<body>
  <div id="box">
    <input type="button" value="按鈕" v-on:click="adjust()">
    <div style="width:100px; height:100px; background: red" v-show="a">
    </div>
  </div>
</body>
</html>

實(shí)例:vue簡(jiǎn)易留言本

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>www.dbjr.com.cn vue簡(jiǎn)易留言本</title>
  <style>
  </style>
  <link rel="stylesheet"  rel="external nofollow" >
  <script src="http://libs.baidu.com/jquery/1.7.2/jquery.min.js"></script>
  <script src="https://cdn.bootcss.com/twitter-bootstrap/2.3.2/js/bootstrap.js"></script>
  <script src="https://cdn.bootcss.com/vue/2.4.4/vue.min.js"></script>
  <script>
    window.onload=function(){
      new Vue({
        el:'#box',
        data:{
          myData:[],
          username:'',
          name:'',
          age:'',
          nowIndex:-100
        },
        methods:{
          add:function(){
            this.myData.push({
              name:this.username,
              age:this.age
            });
            this.username='';
            this.age='';
          },
          deleteMsg:function(n){
            if(n==-2){
              this.myData=[];
            }else{
              this.myData.splice(n,1);
            }
          }
        }
      });
    };
  </script>
</head>
<body>
  <div class="container" id="box">
    <form role="form">
      <div class="form-group">
        <label for="username">用戶名:</label>
        <input type="text" id="username" class="form-control" placeholder="輸入用戶名" v-model="username">
      </div>
      <div class="form-group">
        <label for="age">年 齡:</label>
        <input type="text" id="age" class="form-control" placeholder="輸入年齡" v-model="age">
      </div>
      <div class="form-group">
        <input type="button" value="添加" class="btn btn-primary" v-on:click="add()">
        <input type="reset" value="重置" class="btn btn-danger">
      </div>
    </form>
    <hr>
    <table class="table table-bordered table-hover">
      <caption class="h3 text-info">用戶信息表</caption>
      <tr class="text-danger">
        <th class="text-center">序號(hào)</th>
        <th class="text-center">名字</th>
        <th class="text-center">年齡</th>
        <th class="text-center">操作</th>
      </tr>
      <tr class="text-center" v-for="(item,index) in myData">
        <td>{{index+1}}</td>
        <td>{{item.name}}</td>
        <td>{{item.age}}</td>
        <td>
          <button class="btn btn-primary btn-sm" data-toggle="modal" data-target="#layer" v-on:click="nowIndex=$index">刪除</button>
        </td>
      </tr>
      <tr v-show="myData.length!=0">
        <td colspan="4" class="text-right">
          <button class="btn btn-danger btn-sm" v-on:click="nowIndex=-2" data-toggle="modal" data-target="#layer" >刪除全部</button>
        </td>
      </tr>
      <tr v-show="myData.length==0">
        <td colspan="4" class="text-center text-muted">
          <p>暫無(wú)數(shù)據(jù)....</p>
        </td>
      </tr>
    </table>
    <!--模態(tài)框 彈出框-->
    <div role="dialog" class="modal fade bs-example-modal-sm" id="layer">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">
              <span>&times;</span>
            </button>
            <h4 class="modal-title">確認(rèn)刪除么?</h4>
          </div>
          <div class="modal-body text-right">
            <button data-dismiss="modal" class="btn btn-primary btn-sm">取消</button>
            <button data-dismiss="modal" class="btn btn-danger btn-sm" v-on:click="deleteMsg(nowIndex)">確認(rèn)</button>
          </div>
        </div>
      </div>
    </div>
  </div>
</body>
</html>

運(yùn)行效果:

感興趣的朋友可以使用在線HTML/CSS/JavaScript代碼運(yùn)行工具http://tools.jb51.net/code/HtmlJsRun測(cè)試上述代碼運(yùn)行效果。

希望本文所述對(duì)大家vue.js程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • 詳解vue-meta如何讓你更優(yōu)雅的管理頭部標(biāo)簽

    詳解vue-meta如何讓你更優(yōu)雅的管理頭部標(biāo)簽

    這篇文章主要介紹了詳解vue-meta如何讓你更優(yōu)雅的管理頭部標(biāo)簽,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-01-01
  • Vue 動(dòng)態(tài)生成數(shù)據(jù)字段的實(shí)例

    Vue 動(dòng)態(tài)生成數(shù)據(jù)字段的實(shí)例

    這篇文章主要介紹了Vue 動(dòng)態(tài)生成數(shù)據(jù)字段的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • vue.js組件之間傳遞數(shù)據(jù)的方法

    vue.js組件之間傳遞數(shù)據(jù)的方法

    本篇文章主要介紹了vue.js組件之間傳遞數(shù)據(jù)的方法,組件實(shí)例的作用域是相互獨(dú)立的,如何傳遞數(shù)據(jù)也成了組件的重要知識(shí)點(diǎn)之一,有興趣的可以了解一下
    2017-07-07
  • 詳解Vue雙向數(shù)據(jù)綁定原理解析

    詳解Vue雙向數(shù)據(jù)綁定原理解析

    本篇文章主要介紹了詳解Vue雙向數(shù)據(jù)綁定原理解析 ,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-09-09
  • 基于Vue生產(chǎn)環(huán)境部署詳解

    基于Vue生產(chǎn)環(huán)境部署詳解

    下面小編就為大家?guī)?lái)一篇基于Vue生產(chǎn)環(huán)境部署詳解。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-09-09
  • Vue引入jquery實(shí)現(xiàn)平滑滾動(dòng)到指定位置

    Vue引入jquery實(shí)現(xiàn)平滑滾動(dòng)到指定位置

    這篇文章主要介紹了Vue引入jquery實(shí)現(xiàn)平滑滾動(dòng)到指定位置的效果,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2018-05-05
  • 基于Vue2x的圖片預(yù)覽插件的示例代碼

    基于Vue2x的圖片預(yù)覽插件的示例代碼

    本篇文章主要介紹了基于Vue2x的圖片預(yù)覽插件的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-05-05
  • Vue3+X6流程圖實(shí)現(xiàn)數(shù)據(jù)雙向綁定詳解

    Vue3+X6流程圖實(shí)現(xiàn)數(shù)據(jù)雙向綁定詳解

    這篇文章主要為大家詳細(xì)介紹了Vue3如何結(jié)合X6流程圖實(shí)現(xiàn)數(shù)據(jù)雙向綁定,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-03-03
  • vue父子組件的通信方法(實(shí)例詳解)

    vue父子組件的通信方法(實(shí)例詳解)

    這篇文章主要介紹了vue父子組件的通信的方法,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-11-11
  • vue如何監(jiān)聽(tīng)元素橫向滾動(dòng)到最右側(cè)

    vue如何監(jiān)聽(tīng)元素橫向滾動(dòng)到最右側(cè)

    這篇文章主要介紹了vue如何監(jiān)聽(tīng)元素橫向滾動(dòng)到最右側(cè)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-10-10

最新評(píng)論