Copy
data() {
return {
loading: false
}
},
methods: {
//复制内容到粘贴板
copyToClipboard(elemRef) {
let target;
let succeed = false;
if(this.$refs[elemRef]){
target = this.$refs[elemRef];
// 选择内容
let currentFocus = document.activeElement;
target.focus();
target.setSelectionRange(0, target.value.length);
// 复制内容
try {
succeed = document.execCommand("copy");
} catch (e) {
succeed = false;
}
// 恢复焦点
if (currentFocus && typeof currentFocus.focus === "function") {
currentFocus.focus();
}
}
return succeed;
}
},
clipboard做出了复制功能,但是怎么做出粘贴和剪切?