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 onError() {
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         onError (row) {
20             const h = this.$createElement;
21             this.$notify({
22                 title: row.text + ' 複製失敗',
23                 message: h('i', { style: 'color: teal' }, '聯繫技術吧!')
24             });
25         },

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章