[Vuejs]-Create a full url of another route in my Vue app and copy it into clipboard

0👍

  1. 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 no clipboard.push API). If you really want to use <a>, you must prevent default browser on click behavior (navigating to href)
<a :href="path" @click.prevent.stop="onClick(path)"> Copy link </a>
  1. You are merging your current page’s full URL with the relative url of the route. Use window.location.origin instead of window.location in your computed property

  2. You will need to implement onClick handler to Copy output of a JavaScript variable to the clipboard

Working example

Leave a comment