<input ref="textCopy" value="" style="opacity:0;position:absolute" />
<button @click="textCopy">复制</button>
let textCopy = ref();
const textCopy = () => {
const text = '内容'; // 复制文本内容
const input = textCopy.value;
input.value = text; // 修改input的内容
input.select(); // 选中文本
document.execCommand("copy"); // 浏览器复制
alter("复制成功");
};
注意:input不能直接隐藏,要不没效果,可以用透明度来实现在页面看不到效果。