vuejs2.0如何獲取dom元素自定義屬性值


1.設置定義屬性值  :data-value=".."

<ul class="header-ul">
          <li class="flexcss" v-for="(list,index) in child" :data-value="list.name" @click="changeContent(index,list.name)">{{list.name}}</li>
        </ul>
methods: {
          changeHeaderContent(index,name){
              console.log('cht',index)
              console.log('chaname',name)
}

2.直接獲取

<div class="c-img-box" @click="gotoDetail(name)" :data-value="name">
data () {
    return {
      msg: 'Welcome to Your Vue.js App',
      name:'czj',
    }
  },
gotoDetail:function(ev){
      console.log(ev);
    },

3.通過this.$refs.***獲取

1.目標DOM定義ref值:

2.通過 【this.$refs.***.屬性名】 獲取相關屬性的值:

this.$refs.***   獲取到對應的元素


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM