search

Home  >  Q&A  >  body text

Click event in router-link - Stack Overflow

<li :class="{active: show === 'daily'}">
  <router-link @click="displayArticle('hot')" to="/home/article">日报</router-link> 
</li>

Why does it have no effect if I write it like the above, but I can change it to the following one? router-link Can't events be bound to tags?

<li :class="{active: show === 'hot'}" @click="displayArticle('hot')">
  <router-link  to="/home/article">热门</router-link>  
</li>
巴扎黑巴扎黑2741 days ago583

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-06-12 09:32:57

    router-link will prevent click events

    You can only use @click.native="displayArticle('hot')" in router-link

    Generally do not add it to router-link

    reply
    0
  • 滿天的星座

    滿天的星座2017-06-12 09:32:57

    To bind native events to custom components, you need to add the .nativemodifier document portal

    reply
    0
  • Cancelreply