记录一下使用到的东西,将文字识别结果一键复制
代码
// 文本复制
copyText () {
//使用textarea的原因是能进行换行,input不支持换行
var copyTextArea = document.createElement("textarea");
//自定义复制内容拼接
var str = `银行卡卡号 ${this.recognizeList.card_num}\n有效期 ${this.recognizeList.date}\n银行名称 ${this.recognizeList.card_name}\n银行卡类型 ${this.recognizeList.card_type}`;
copyTextArea.value = str;
document.body.appendChild(copyTextArea);
copyTextArea.select();
try {
var copyed = document.execCommand("copy");
if (copyed) {
document.body.removeChild(copyTextArea);
//这里是封装的提示框,可以换成自己使用的提示框
this.$notifySuccess({
title: '操作成功',
msg: '复制成功'
})
}
} catch {
this.$notifyError({
title: "操作失败",
msg: '复制失败,请检查浏览器兼容',
});
}
},