复制到剪切板
const copyText = () => {
let txt = '这里是复制的一段内容。'
try {
const str = txt;
const input = document.createElement("input");
document.body.appendChild(input);
input.value = str;
input.setAttribute("readOnly", "readOnly");
input.select();
document.execCommand("Copy");
document.body.removeChild(input);
showToast({
type: "success",
message: "复制成功",
duration: 1500,
});
} catch (error) {
showToast({
type: "fail",
message: "复制失败",
duration: 1500,
});
}
};