2017-07-13 83 views
0

有什麼辦法可以有多個v-on:點擊同一項目上的事件? 我試圖同時顯示/隱藏切換導航,並對切換導航的項目執行css動畫。Vue.js多個v-on:點擊事件

<template> 
    <div> 
     <nav v-if="seen"> 
      <ul> 
       <li><a href="#front" v-smooth-scroll>forside</a></li> 
       <li><a href="#services" v-smooth-scroll>ydelser</a></li> 
       <li><a href="#cases" v-smooth-scroll>cases</a></li> 
       <li><a href="#contact" v-smooth-scroll>kontakt</a></li> 
      </ul> 
     </nav> 
     <div @click="seen = !seen" @click="setActive" id="burger-container"> 
      <div id="burger"> 
      <span>&nbsp;</span> 
      <span>&nbsp;</span> 
      <span>&nbsp;</span> 
      </div> 
     </div>  
    </div> 
</template> 

<script> 
    export default { 
     data() { 
     return { 
      seen: false 
     } 
     }, 
     methods: { 
     setActive (event) { 
      event.target.classList.toggle('open') 
     } 
     } 
    } 
</script> 
+0

的可能的複製[如何調用多個功能與V系列:點擊](HTTPS:/ /stackoverflow.com/questions/38744932/how-to-call-multiple-function-with-v-onclick) –

回答

2

你爲什麼不只是第二個事件添加到函數,就像這樣:

methods: { 
    setActive (event) { 
     event.target.classList.toggle('open') 
     this.seen = !this.seen 
    } 
    }