js 复制功能

 
html
<span class="clipboard-btn copy-btn" @click="addcopy()" value="this.inputValue">Copiar<input type="hidden" id='copyBtn' value="d.didiglobal.com/subsellos" @click="addcopy()"></span>
 
js
addcopy(event){
var i = document.createElement('input')
document.body.appendChild(i)
i.value = 'https://d.didiglobal.com/subsellos'
// i.focus()
i.select()
if (document.execCommand('copy')) {
document.execCommand('copy')
this.showToast({
type: "correct",
text: 'El link se copió correctamente.', //链接复制成功
});
Omega.trackEvent('ibt_copyclick_ck', '', {
user_id:urlQuery.user_id,
});
}else{
this.showToast({
type: "error",
text: 'No fue posible copiar el link. ', //链接复制失败
});
}
document.body.removeChild(i)
}
原文地址:https://www.cnblogs.com/restart77/p/15609206.html