最近遇到一个需求,是需要把用户选择的几个变量,按照要求的格式拼成一个字符串,支持用户点击按钮复制出来
实现方式有多种,由于不想下载插件,这里用JS方式去实现
函数接收的 value 就是我处理好的拼接字符串
copy(value) {
const input = document.createElement("input");
input.setAttribute("value", value);
document.body.appendChild(input);
input.select();
document.execCommand("copy");
document.body.removeChild(input);
this.$message.success('复制成功')
},
调用函数后,ctrl+v 即可粘贴成功~~