初創(chuàng)公司網(wǎng)站設(shè)計蘇州百度移動端點贊排名軟件
開發(fā)環(huán)境下使用navigator.clipboard進(jìn)行復(fù)制操作,打包部署到服務(wù)器上后,發(fā)現(xiàn)該功能顯示為undefined;查相關(guān)資料后,發(fā)現(xiàn)clipboard只有在安全域名下才可以訪問(https、localhost),在http域名下只能得到undefined;
解決方案如下:
let clipboard = navigator.clipboard || {writeText: (text) => {let copyInput = document.createElement('input');copyInput.value = text;document.body.appendChild(copyInput);copyInput.select();document.execCommand('copy');document.body.removeChild(copyInput);}}if (clipboard) {await clipboard.writeText(this.formData.url);this.$message.success('復(fù)制成功');}