0👍
- If you don’t want browser to open the link, why use
<a>
in the first place ? You will need some kind of textbox anyway, because browsers do not allow JavaScript to put something into clipboard (there is noclipboard.push
API). If you really want to use<a>
, you must prevent default browseron click
behavior (navigating to href)
<a :href="path" @click.prevent.stop="onClick(path)"> Copy link </a>
-
You are merging your current page’s full URL with the relative url of the route. Use
window.location.origin
instead ofwindow.location
in your computed property -
You will need to implement
onClick
handler to Copy output of a JavaScript variable to the clipboard
Source:stackexchange.com