Nuxt.js: Can't prevent middle click to open href in new tab

Created on 16 Apr 2019  路  5Comments  路  Source: nuxt/nuxt.js

Version

v2.5.1

Reproduction link

https://ykrkz6k081.sse.codesandbox.io/

Steps to reproduce

<template><a href="https://google.com"
        @click.prevent
       @click.middle.prevent.stop="goto" 
        >Should not open with
        middle click</a>

<script>
methiods:{
   goto(e){
      e.preventDefault();
      return false
    }

What is expected ?

should block middle click from opening in new tab

What is actually happening?

Chrome opens link in new tab.

Additional comments?

Left click works correctly (is blocking with .prevent). Middle isn't;

This bug report is available on Nuxt community (#c9062)
bug-report

All 5 comments

Link to editor of codesandbox https://codesandbox.io/s/ykrkz6k081?fontsize=14

Hello @ambrt seems like this is an issue specifically within the Vue.js. I'll open a PR with the Vue team. A workaround for this would be to set it to this @auxclick.prevent.stop='goto' instead of listening to the @click, I hope this helps you. 馃槃

@asg5704 Thanks, it works馃槂 . Btw,is @auxclick something internal in Vue? I couldn't find anything in docs about it. (I'm closing issue but still curious )

@ambrt, No it is not in the Vue docs.

auxclick is the name of the event supported by browsers - https://developer.mozilla.org/en-US/docs/Web/API/Element/auxclick_event
It doesn't need to be listed in Vue docs as Vue can handle any arbitrarily named event, this one just being one of them.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

uptownhr picture uptownhr  路  3Comments

lazycrazy picture lazycrazy  路  3Comments

gary149 picture gary149  路  3Comments

bimohxh picture bimohxh  路  3Comments

bimohxh picture bimohxh  路  3Comments