export default function h5Copy(content) {
console.log(content);
if (!document.queryCommandSupported('copy')) {
// 不支持
alert('您当前的应用环境不支持自动复制内容......')
return false
}
let textarea = document.createElement("textarea")
textarea.value = content
textarea.readOnly = "readOnly"
document.body.appendChild(textarea)
textarea.select() // 选择对象
textarea.setSelectionRange(0, content.length) //复制的内容的范围
let result = document.execCommand("copy") // 执行浏览器复制命令
textarea.remove()
return result
}
使用
import h5Copy from "@/util/copy";
let res = h5Copy(’content‘);
if (res) {
this.$message({
type: "success",
message: "复制成功",
});
}