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>
2.
methods: { changeHeaderContent(index,name){ console.log('cht',index) console.log('chaname',name) }
上面是迴圈體中獲取。
直接獲取
<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);
},