//复制短连接
Link(id) {
let _this = this
http.get(`/api/Product/CopyUrl?id=${id}`).then(function (res) {
_this.copyUrl(res.data.sortLable, res.data.introduction, res.data.shorturl)
}).catch(function (err) {
_this.$message.error(err);
})
},
//实现复制功能
copyUrl(sortLable,introduction, shorturl) {
// 模拟 输入框
var cInput = document.createElement("textarea");
if (introduction != "" && introduction != undefined) {
introduction = introduction;
}
cInput.value = sortLable + " " + shorturl + "\n" + introduction;
document.body.appendChild(cInput);
cInput.select(); // 选取文本框内容
// 执行浏览器复制命令
// 复制命令会将当前选中的内容复制到剪切板中(这里就是创建的input标签)
// Input要在正常的编辑状态下原生复制方法才会生效
document.execCommand("copy");
this.$message({
type: "success",
message: "複製成功"
});
// 复制成功后再将构造的标签 移除
document.body.removeChild(cInput);
},
实现复制文本
最新推荐文章于 2023-06-11 10:08:15 发布