2017-05-19 33 views

回答

6

當您試圖直接操縱DOM時,在Vue中這不是一個好習慣。如果你想顯示/隱藏一個元素,你應該使用v-ifv-show指令。

無論如何,你可以訪問event對象是這樣的:

new Vue({ 
 
    el: '#app', 
 
    methods: { 
 
    logme: function(event) { // a regular event object is passed by $event in template 
 
     console.log(event.target.parentElement) // parent element 
 
    } 
 
    } 
 
});
<script src="https://unpkg.com/vue/dist/vue.js"></script> 
 

 
<div id="app"> 
 
    <div class="hello"> 
 
    <button @click="logme($event)">Click me</button> 
 
    </div> 
 
</div>

+0

感謝wostex,它的工作現在。這個項目是特定的,它已經用jQuery製作了。所以,我的工作是重寫Vue。非常感謝! – mmiloshev

+0

@Glavar如果這個答案適合你,你應該接受它。 – Bert