判读网络状态
var img = new Image(); img.src = 'https://www.baidu.com/favicon.ico?_t=' + Date.now(); img.οnlοad=function(){ if (callback) callback(true) }; img.οnerrοr=function(){ if (callback) callback(false) };
实现复制(防止断网了继续复制)
copybox.oncopy = () => { let routeName = vm.$route.name; if(pageConfig.includes(routeName)){ if(vm.remaminCount<=0){ vm.copy("Please No Copies"); this.$Message.warning("您当天的复制次数已经用完"); return false } let selectedStr = window.getSelection().toString(); let copyContent = selectedStr.replace(/\s*/g,''); vm.copy("Please No Copies"); let params ={ activityId: this.$route.params.id, copyContent:copyContent, page:routeName, contentLength:copyContent.length, } try{ vm.addLog(params,selectedStr) }catch (e) { return false } } }
实现假复制
copy(val) { var oInput = document.createElement('input'); oInput.value = val; document.body.appendChild(oInput); oInput.select(); // 选择对象 document.execCommand("Copy"); // 执行浏览器复制命令 oInput.className = 'oInput'; oInput.style.display='none'; },