快下班了,发现一个好用的方法,记录下来分享给大家
因为要实现,点击列表按钮,复制下载链接,后端让我自己直接去拼下载地址,网上找了一圈,发现这个方法不错,分享出来给大家使用
<el-button type="primary" round size="mini" @click="copyUrl">复制url</el-button>
//js
copyUrl() {
const input = document.createElement('input')
document.body.appendChild(input)
input.setAttribute('value',"这里可以写变量或者要复制的字符串内容")
input.select()
if (document.execCommand('copy')) {
document.execCommand('copy')
}
document.body.removeChild(input)