vue中clipboard插件的使用
馨er BOSS

vue中clipboard插件的使用

1 安装

1
npm i clipboard -s

2 使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<template>
<div style="margin:0 auto;width: 80%">
<el-table :data="dataList">
<el-table-column label="人员名称" prop="name"></el-table-column>
<el-table-column label="头像" prop="url"></el-table-column>
<el-table-column label="工号" prop="number"></el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
<el-button @click="copyAvatarurl(scope.row)" class="copy">复制头像url</el-button>
</template>
</el-table-column>
</el-table>
</div>
</template>
<script>
import Clipboard from 'clipboard'

export default {
name: 'copyTest',
data () {
return {
dataList: [
{'name': '小明', 'url': 'https://www.xiaomingtouxiang.com/',number:'9527'},
{'name': '小黑', 'url': 'https://www.xiaoheitouxiang.com/',number:'9526'},
{'name': '小白', 'url': 'https://www.xiaobaitouxiang.com/',number:'9525'}
]
}
},
methods: {
copyAvatarurl (e) {
let clipboard = new Clipboard('.copy', {
text: function () {
return e.avatar
}
})
clipboard.on('success', e => {
this.$message({message: '复制成功', showClose: true, type: 'success'})
clipboard.destroy()
})
clipboard.on('error', e => {
this.$message({message: '复制失败,', showClose: true, type: 'error'})
clipboard.destroy()
})
}
}
}
</script>
  • 本文标题:vue中clipboard插件的使用
  • 本文作者:馨er
  • 创建时间:2022-08-03 23:43:01
  • 本文链接:https://sjxbbd.vercel.app/2022/08/03/b24a825a7e6e/
  • 版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!