el-table 使用复制功能vue-clipboard2
作者:互联网
安装
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