vue中点击按钮复制内容

<button @click="copyUrl">复制url</button>   

  

//js
    copyUrl() {
      const input = document.createElement('input')
      document.body.appendChild(input)
      input.setAttribute('value',"这里可以写变量或者要复制的字符串内容")
      input.select()
      if (document.execCommand('copy')) {
        document.execCommand('copy')
      }
      document.body.removeChild(input)

  

posted @ 2019-05-15 10:48  阳光下那抹高傲的轻笑  阅读(802)  评论(0)    收藏  举报