遇到ie11不兼容复制功能。谷歌正常复制,ie复制后无反应。查询资料ie要调用剪切板,跟谷歌不一样
1、先对谷歌跟IE做区分
// 判断是否是IE
if (!!window.ActiveXObject || "ActiveXObject" in window) {
} else {
}
2、当你浏览器是IE的时候
if (window.clipboardData) {
//清空操作系统粘贴板
window.clipboardData.clearData();
//将需要复制的内容复制到操作系统粘贴板
window.clipboardData.setData("Text", Val);
this.$message({
message: '复制成功',
type: 'success'
});
}
3、当你浏览器是谷歌、火狐等等。用正常execCommand
var _input = document.createElement('input')
_input.value = Val
document.body.appendChild(_input)
_input.select()
document.execCommand('Copy')
_input.remove()
this.$message({
message: '复制成功',
type: 'success'
});