<div @click="copyWX(18888888888)">一键复制</div>
//点击事件
copyWx(item) {
// 模拟 输入框
var cInput = document.createElement("input");
cInput.value = item;
document.body.appendChild(cInput);
cInput.select(); // 选取文本框内容
// 执行浏览器复制命令
// 复制命令会将当前选中的内容复制到剪切板中(这里就是创建的input标签)
// Input要在正常的编辑状态下原生复制方法才会生效
document.execCommand("copy");
this.$toast({
type: "success",
message: "单号复制成功",
});
// 复制成功后再将构造的标签 移除
document.body.removeChild(cInput);
},
一键复制 — vue
最新推荐文章于 2024-08-07 17:20:33 发布