// 复制字符串
copyText(text) {
var textarea = document.createElement("input");//创建input对象
var currentFocus = document.activeElement;//当前获得焦点的元素
document.body.appendChild(textarea);//添加元素
textarea.value = text;
textarea.focus();
if (textarea.setSelectionRange)
textarea.setSelectionRange(0, textarea.value.length);//获取光标起始位置到结束位置
else
textarea.select();
let flag = ''
try {
flag = document.execCommand("copy");//执行复制
} catch (eo) {
flag = false;
}
document.body.removeChild(textarea);//删除元素
currentFocus.focus();
return flag;
}
// 执行
copyLink() {
let str = 'https://www.wxwhouse.com/wxwH5/#/downApp'
let flag = this.copyText(str); //传递文本,项目需要拼接str1和str2,复制的是str
if(flag) {
this.$toast.success('复制成功!')
} else {
this.$toast.fail('复制失败!')
}
},