1、效果图:

2、在项目utils目录下创建index.js

然后创建如下拷贝方法
export function copyText(copytext) {
const text = document.createElement('input'); // 创建节点
text.setAttribute('readonly', 'readonly');
text.value = copytext; // 赋值
document.body.appendChild(text); // 插入节点
text.setSelectionRange(0, text.value.length);
text.select(); // 选中节点
document.execCommand('copy'); // 执行浏览器复制方法
if (document.body.removeChild(text)) {
this.$message({ type: 'success', message: '复制成功' })
} else {
this.$message({ type: 'error', message: '复制失败' })
}
}
3、在main.js中引入该方法,并挂载
import {isAuth, hasRole, copyText} from '@/utils'
Vue.prototype.copyText = copyText
4、在el-table-cloumn中使用
<el-table-column prop="purchaseOrderNo" header-align="center" align="center" label="采购订单号" width="140" show-overflow-tooltip>
<template slot-scope="scope">
<el-tag type="success" size="mini" @click="copyText(scope.row.purchaseOrderNo)" >
复制
</el-tag>
{{ scope.row.purchaseOrderNo}}
</template>
</el-table-column>
1205




被折叠的 条评论
为什么被折叠?



