项目开发中遇到该场景,如果有原创内容地址,请告知,谢谢。
项目场景:
项目中有一链接地址,点击按钮,将该链接内容复制。
解决方案:
一、vue代码
<el-button
size="small"
type="primary"
@click.stop="copyAddress"
>复制地址</el-button>
二、js部分
copyAddress() {
let oInput = document.createElement("input");
//这边为链接地址this.liveLink='www.baidu.com'
oInput.value = this.liveLink;
document.body.appendChild(oInput);
oInput.select();
console.log(oInput.value);
document.execCommand("Copy");
oInput.remove();
this.$message({
message: "复制成功",
type: "success",
});
},
在Vue项目中,可以通过创建隐藏input元素,设置其value为链接地址,然后选中并执行复制命令来实现在点击按钮时复制链接。具体做法包括在模板中添加按钮触发事件,以及在JavaScript中实现复制逻辑,最后弹出提示信息告知用户复制成功。
1261

被折叠的 条评论
为什么被折叠?



