最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue v-for 點擊當前行,獲取當前行數(shù)據(jù)及event當前事件對象的操作

 更新時間:2020年09月10日 10:01:51   作者:好巧.  
這篇文章主要介紹了vue v-for 點擊當前行,獲取當前行數(shù)據(jù)及event當前事件對象的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

前言

在 v-for 循環(huán)語句上,定義一個點擊事件 傳入兩個參數(shù)(當行數(shù)據(jù)、當前事件對象),如下代碼片段,當前事件對象必須加上 ‘$' 符號

<template>
 <div>
  <ul>
   <li
    v-for="(item, index) in arrData"
    :key="index"
    @click="operate(item, $event)"
   >
    {{ item.title }}
   </li>
  </ul>
 </div>
</template>

<script>
export default {
 data() {
  return {
   arrData: [
    { id: 1, title: '第一條數(shù)據(jù)' },
    { id: 2, title: '第二條數(shù)據(jù)' }
   ]
  };
 },
 methods: {
  operate(item, event) {
   console.log(item);
   console.log(event);
  }
 }
};
</script>

不加'$‘報錯:

加上'$‘: 點擊行之后獲得當前行數(shù)據(jù) 以及當前事件對象

如果本篇文章對你有幫助的話,很高興能夠幫助上你。

補充知識:vue獲取當前點擊對象的下標,和當前點擊對象的內(nèi)容

如下所示:

<li v-for="(item,index) in tabList" v-on:click="addClass(index,$event)" >{{item.title}}</li>

data里面聲明:

data() {
  return {
   tabList: [
    { id: 0, title: "首頁1" },
    { id: 1, title: "首頁2" },
    { id: 2, title: "首頁3" }
   ],
   current:0
  };
 },
 methods: {
  addClass: function(index,event) {
   this.current = index;
   //獲取點擊對象   
   var el = event.currentTarget;
   console.log("當前對象的內(nèi)容:"+el.innerHTML);
   console.log(this.current)
  }

以上這篇vue v-for 點擊當前行,獲取當前行數(shù)據(jù)及event當前事件對象的操作就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

最新評論

荥经县| 高雄县| 田阳县| 大方县| 石台县| 延川县| 阳城县| 荥阳市| 法库县| 广河县| 华亭县| 莱阳市| 阳西县| 宜兴市| 霍城县| 柳州市| 汉源县| 从江县| 神池县| 喀喇沁旗| 灵山县| 云霄县| 商城县| 东乌珠穆沁旗| 深水埗区| 江口县| 田林县| 金阳县| 济源市| 灵寿县| 台安县| 合川市| 阿拉尔市| 渑池县| 阿城市| 连城县| 屏山县| 潞城市| 巨鹿县| 清苑县| 湘西|