本文主要是介绍vue2,vue3基于elementUI的el-table实现复制粘贴功能,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
vue2,vue3基于elementUI的el-table实现复制粘贴功能
- vue2
- vue3
1、先声明一下,为啥又有vue2和vue3呢,因为老项目要改造成vite+ts+vue3,时间紧,来不及全部转换,所以就有了componentApi和optionsApi共存的情况
2、单页面使用,全局未实现
vue2
- 既然是基于el-table呢就有现成的methods可以使用
@row-contextmenu="rowContextmenu"
@row-click="rowClick"
<template><el-tableref="multipleTableRef"v-loading="loading":data="state.dataList"style="width: 100%; margin-bottom: 20px"border:cell-style="cellStyle"@sort-change="sortChange":header-cell-style="headerCellStyle"@selection-change="handleSelectionChange"@row-contextmenu="rowContextmenu"@cell-mouse-leave="cellMouseLeave"@row-click="rowClick"><el-table-column align="center" prop="status" label="是否正确" show-overflow-tooltip width="130"><template #default="{ row }"><span v-if="row.status === 1">正确</span><span v-if="row.status === 2">错误</span></template></el-table-column>
</el-table><div v-if="position.show":style="{ position: 'fixed', top: position.y + 'px', left: position.x + 'px', zIndex: 9999, display: 'flex',justifyContent:'center',alignItems:'center',flexFlow:'column',borderRadius:'5px' }"class="context-menu"><!-- 菜单内容 --><span class="posItem" @click="copyText('column')"><el-icon><DocumentCopy/></el-icon>复制当前行</span><span class="posItem" @click="copyText('row')"><el-icon><DocumentCopy/></el-icon>复制当前列</span></div>
</template>
<script>
export default {date() {return {position: {x: 0,y: 0,show: false,row: null,column: null,},columnList: [ // 需要复制的 prop'orderCodes','bookCode','orderExecManagerName','logisticsManagerName','customerName','startPortName','endPortName','endPortCountryName','outCountryName','contractDealstyle','shipMentName','requireWeek','expectEtd','bookArrivalDate','vendorName','bookShipName','preBookStatusName','actualVolumeBoxType','cntCount','forwardAgent','forwardAgentContact','goodTypeName','deptName','prodName','bookTime','bookTrustTime','requireMonth','requireYear','bookComments','forwardAgent','agentName','customsName','bookingRemark',
这篇关于vue2,vue3基于elementUI的el-table实现复制粘贴功能的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!