亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

javascript - Use vue.js to achieve the effect: click li, get the html value of the current click li, and the parameter this becomes the window object?
曾經(jīng)蠟筆沒(méi)有小新
曾經(jīng)蠟筆沒(méi)有小新 2017-06-14 10:54:14
0
4
1064

The effect to be achieved:

  • Click li to get the html value of the currently clicked li;

Main code

<body>
<p id="page">
    <ul>
        <li v-on:click="aa(this)" v-for="item in items">{{item}}</li>
    </ul>
</p>
<script type="text/javascript">
new Vue({
  el: '#page',
  data: {
        items:[11,22,33,44]
  },
  methods:{
    aa:function(obj){
        console.log(obj);  //打印出來(lái)的是 window對(duì)象?
        alert(obj.html());   //找不到點(diǎn)擊的值;
    }
  }
})
</script>
</body>

Problem Description:

The this passed after clicking li is printed as the window object, not the li object, so the object cannot be found; how to pass the current li object to js?

曾經(jīng)蠟筆沒(méi)有小新
曾經(jīng)蠟筆沒(méi)有小新

reply all(4)
小葫蘆

Read the documentation carefully...don't make assumptions about these inexplicable usages.

When an inline event needs to access the original event object, just add the $event parameter to it. Like this:

<li v-on:click="aa($event)" v-for="item in items">{{item}}</li>

To get the object of the current li tag, just read the currentTarget attribute under the event object, that is, event.currentTarget.

女神的閨蜜愛(ài)上我
<li @click="aa(item)" v-for="item in items">{{item}}</li>
aa(item) {
  console.log(item) // 當(dāng)前l(fā)i的內(nèi)容
}
左手右手慢動(dòng)作

Add a ref attribute to li and then get the dom node through this.$refs in methods

typecho

Test possible:

<li @click="aa($event)" v-for="item in items">{{item}}</li>
  methods:{
    aa:function(event){
        console.log(event.target.innerHTML);
    }
  }
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template