<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("复制成功");
};
Note: The input cannot be hidden directly, or it has no effect, you can use transparency to make the effect invisible on the page.