实现点击链接复制其地址的功能(分享链接)

在PC页面中实现点击一个链接,复制到粘贴板上

思路:
1、创建一个新标签input
2、把要复制的链接添加里面
3、通过document.execCommand函数将其复制到粘贴板上
4、移除input

execComman 函数好像只能复制input里的 value值(仅供参考)

 shareUrl(share) {
 		//share 链接地址
      var tag = document.createElement("input");
      tag.setAttribute("id", "share_url");
      tag.value = share;
      document.getElementsByTagName("body")[0].appendChild(tag);
      document.getElementById("share_url").select();
      document.execCommand("copy");
      document.getElementById("share_url").remove();
      this.$message.success("复制成功");
    },

版权声明:本文为weixin_47953779原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。