第一步 需要有个按钮
此处使用的elementUI
<el-button type="text" icon="el-icon-copy-document" @click="doCopy()" ></el-button>
第二步 直接在methods里定义方法
doCopy() {
const input = document.createElement("input");
input.value = "https://www.zhihu.com/"; //将需要复制的内容赋值给input框,此处也可以是变量自己直接赋值就好了
document.body.appendChild(input);
input.select(); //选中输入框
document.execCommand("Copy"); //复制当前选中文本到前切板
document.body.removeChild(input);
this.$message.success("复制成功");
}
###复制完成就可以去粘贴啦