copy(text) {
// text: 文本內(nèi)容
window.navigator.clipboard
.writeText(text)
.then(() => {
ui.success('復制成功');
})
.catch(() => {
const input = document.createElement('input');
document.body.appendChild(input);
input.value = text;
input.focus();
input.select();
const result = document.execCommand('copy');
input.style.display = 'none';
if (result === 'unsuccessful') {
ui.error('復制失敗,請手動復制!');
return;
}
ui.success('復制成功');
});
}
注意:在192.168.xx.xx地址上使用這個方法獲取不到clipboard,復制會失敗。
需要是localhost、https或者127.0.0.1。