ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

el-table 使用复制功能vue-clipboard2

2022-05-17 11:31:23  阅读:164  来源: 互联网

标签:el vue title 复制 notify clipboard2 row


安装

1 npm install --save vue-clipboard2
2 
3 yarn add --save vue-clipboard2

引入

1 import Vue from 'vue'
2 
3 import VueClipboard from 'vue-clipboard2'
4 
5 Vue.use(VueClipboard)

表格中使用

@cell-dblclick="celldblclick"

1 <el-table :data="topics" :stripe="true"  border max-height="550"   style="width: 100%" @sort-change="sortChange" :sort-orders="['ascending', 'descending']"
2                       cell-class-name="cell"       @cell-dblclick="celldblclick" >
3     <el-table-column width="100" type="index"></el-table-column>
4 </el-table>
 1 celldblclick (row, column, cell, event) {
 2    this.$copyText(row[column.property]).then(e=> {
 3        this.onCopy()
 4    }, function (e) {
 5        this.onError()
 6    })
 7 },
 8 onCopy() {
 9    this.$notify({title: '成功', message: '复制成功!', type: 'success', offset: 50, duration: 2000})
10 },
11 one rror() {
12    this.$notify({title: '失败', message: '复制失败!', type: 'error', offset: 50, duration: 2000})
13 }
1 <el-table-column prop="type" label="操作" width="280">
2                 <template slot-scope="{row, $index}">
3                     <el-popover placement="bottom" width="50" trigger="click">
4                         <div class="copy_link" type="text" v-clipboard:copy="copylink" v-clipboard:success="onCopy" v-clipboard:error="onError"><i class="el-icon-link"></i> <span class="copybtn">复制链接</span></div>
5                         <el-button slot="reference" type="text" size="small" @click="genLink(row.taskId)">生成链接</el-button>
6                     </el-popover>
7                 </template>
8             </el-table-column>
 1 // 生成链接
 2         genLink (id) {
 3             throttle(async () => {
 4                 const data = await this.$http({
 5                     url: `/api/genLink/${id}`,
 6                     method: 'post'
 7                 })
 8                 this.copylink = data
 9             }, 500)
10         },
11         onCopy (row) {
12             const h = this.$createElement;
13             this.$notify({
14                 title: row.text + ' 复制成功',
15                 message: h('i', { style: 'color: teal' }, '已复制到剪贴板,请直接去ctrl+V 粘贴吧!')
16             });
17         },
18         // 复制失败
19         one rror (row) {
20             const h = this.$createElement;
21             this.$notify({
22                 title: row.text + ' 复制失败',
23                 message: h('i', { style: 'color: teal' }, '联系技术吧!')
24             });
25         },

 

标签:el,vue,title,复制,notify,clipboard2,row
来源: https://www.cnblogs.com/chen-cheng/p/16280129.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有