vue获取当前元素

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue获取当前元素</title>
<script src="https://cdn.bootcss.com/vue/2.2.2/vue.min.js"></script>
</head>
<body>
<div id="app">
    <button @click='btnClick'>按钮</button>
</div>

<script>
// 创建根实例
new Vue({
  el: '#app',
  methods: {
    btnClick: function (e) {
      var el = e.target;
      el.style.backgroundColor = 'green';
      console.log(el);
    }
  }
})
</script>
</body>
</html>

 

posted @ 2017-09-20 11:17  潇影D  阅读(1616)  评论(0编辑  收藏  举报