function copy(invite_code) {
var text = document.createElement("input");
text.id = 'webcopyinput';
text.value = invite_code;
text.style.position = 'fixed';
text.style.top = '-10000px';
document.body.appendChild(text);
var copied = false;
console.log("Copy Init");
var copyEvent = function () {
if (!copied) {
text.focus();//给input输入框聚焦
text.setSelectionRange(0, text.value.length);//设置input框选中的范围
copied = document.execCommand('Copy');//执行复制操作
text.blur();
alert(copied);
copied=false;
}
}
var btn=document.querySelector('#copy');
btn.addEventListener('click', copyEvent, true);
}
export default copy;
1、给需要点击复制的按钮添加id="copy"的属性
2、把需要复制的值直接传值给这个方法即可