首页 > 其他分享 >vue使用右击复制功能

vue使用右击复制功能

时间:2024-05-27 15:25:56浏览次数:12  
标签:右击 vue name code color age sex 复制 address

 

 

使用的库xe-clipboard

右击复制的

 

实际使用到的库是

xe-clipboard   参考的https://vxetable.cn/v4/#/table/advanced/menu
<template>
  <div>
    <vxe-table
      border
      show-footer
      :row-config="{isCurrent: true}"
      :column-config="{isCurrent: true}"
      :footer-method="footerMethod"
      :data="tableData"
      :menu-config="menuConfig"
      @menu-click="contextMenuClickEvent"
    >
      <vxe-column type="seq" width="60"></vxe-column>
      <vxe-column field="name" title="Name" sortable></vxe-column>
      <vxe-column field="sex" title="Sex"></vxe-column>
      <vxe-column field="age" title="Age"></vxe-column>
      <vxe-column field="address" title="Address"></vxe-column>
    </vxe-table>
  </div>
</template>

<script lang="ts" setup>
import {ref, reactive} from 'vue';
import {VXETable, VxeTablePropTypes, VxeColumnPropTypes, VxeTableEvents} from 'vxe-table';
import XEClipboard from 'xe-clipboard';

interface RowVO {
  id: number;
  name: string;
  role: string;
  sex: string;
  age: number;
  address: string;
}

const tableData = ref<RowVO[]>([
  {id: 10001, name: 'Test1', role: 'Develop', sex: 'Man', age: 28, address: 'test abc'},
  {id: 10002, name: 'Test2', role: 'Test', sex: 'Women', age: 22, address: 'Guangzhou'},
  {id: 10003, name: 'Test3', role: 'PM', sex: 'Man', age: 32, address: 'Shanghai'},
  {id: 10004, name: 'Test4', role: 'Designer', sex: 'Women', age: 36, address: 'Guangzhou'},
  {id: 10005, name: 'Test5', role: 'Develop', sex: 'Women', age: 24, address: 'Shanghai'},
  {id: 10006, name: 'Test6', role: 'Designer', sex: 'Man', age: 34, address: 'test abc'}
]);

const menuConfig = reactive<VxeTablePropTypes.MenuConfig<RowVO>>({
  className: 'my-menus',
  header: {
    options: [[{code: 'exportAll', name: '导出所有.csv'}]]
  },
  body: {
    options: [
      [{code: 'copy', name: '复制', prefixIcon: 'vxe-icon-copy', className: 'my-copy-item'}],
      [
        {code: 'remove', name: '删除', prefixIcon: 'vxe-icon-delete-fill color-red'},
        {
          name: '筛选',
          children: [
            {code: 'clearFilter', name: '清除筛选'},
            {code: 'filterSelect', name: '按所选单元格的值筛选'}
          ]
        },
        {
          code: 'sort',
          name: '排序',
          prefixIcon: 'vxe-icon-sort color-blue',
          children: [
            {code: 'clearSort', name: '清除排序'},
            {code: 'sortAsc', name: '升序', prefixIcon: 'vxe-icon-sort-alpha-asc color-orange'},
            {code: 'sortDesc', name: '倒序', prefixIcon: 'vxe-icon-sort-alpha-desc color-orange'}
          ]
        },
        {code: 'print', name: '打印', disabled: true}
      ]
    ]
  },
  footer: {
    options: [[{code: 'clearAll', name: '清空数据'}]]
  }
});

const contextMenuClickEvent: VxeTableEvents.MenuClick<RowVO> = ({menu, row, column}) => {
  switch (menu.code) {
    case 'copy':
      // 示例
      if (row && column) {
        if (XEClipboard.copy(row[column.field])) {
          VXETable.modal.message({content: '已复制到剪贴板!', status: 'success'});
        }
      }
      break;
    default:
      VXETable.modal.alert(`点击了 ${menu.name} 选项`);
  }
};

const meanNum = (list: RowVO[], field: VxeColumnPropTypes.Field) => {
  let count = 0;
  list.forEach((item) => {
    count += Number(item[field]);
  });
  return count / list.length;
};

const footerMethod: VxeTablePropTypes.FooterMethod<RowVO> = ({columns, data}) => {
  return [
    columns.map((column, columnIndex) => {
      if (columnIndex === 0) {
        return '平均';
      }
      if (['age', 'rate'].includes(column.field)) {
        return meanNum(data, column.field);
      }
      return null;
    })
  ];
};
</script>

<style lang="scss">
.my-menus {
  background-color: #f8f8f9;
}
.my-menus .vxe-ctxmenu--link {
  width: 200px;
}
.my-copy-item {
  font-weight: 700;
  font-style: oblique;
}
.color-red {
  color: red;
}
.color-blue {
  color: blue;
}
.color-orange {
  color: orange;
}
</style>

 

 

标签:右击,vue,name,code,color,age,sex,复制,address
From: https://www.cnblogs.com/hechunfeng/p/18215567

相关文章

  • VUE学习笔记(三)
    本小节为设置跨域和axios请求和获取数据设置跨域,在vue.config.js添加devServer配置const{defineConfig}=require("@vue/cli-service");module.exports=defineConfig({transpileDependencies:true,devServer:{proxy:{"/api":{target:&q......
  • VUE学习笔记(二)
    本小节为搭建布局页和分类页面需要使用到element-plus,添加指令npminstallelement-plus--save布局页从elementplus官网找到布局,粘贴过来<template><el-containerclass="layout-container-demo"><el-asidewidth="200px"><el-scrollbar><divclass=&qu......
  • 基于SpringBoot+Vue的实验室管理系统设计与实现毕设(文档+源码)
            目录一、项目介绍二、开发环境三、功能介绍四、核心代码五、效果图六、源码获取:        大家好呀,我是一个混迹在java圈的码农。今天要和大家分享的是一款基于SpringBoot+Vue的实验室管理系统,项目源码请点击文章末尾联系我哦~目前有各类成品......
  • 基于SpringBoot+Vue的火车订票管理系统设计与实现毕设(文档+源码)
            目录一、项目介绍二、开发环境三、功能介绍四、核心代码五、效果图六、源码获取:        大家好呀,我是一个混迹在java圈的码农。今天要和大家分享的是一款基于SpringBoot+Vue的火车订票管理系统,项目源码请点击文章末尾联系我哦~目前有各类成品......
  • vue测试环境打包文件不添加hash和生产环境打包不一致
    npmrunbuild:testnpmrunbuild:pro测试环境打包出来文件和生产包有差异.env.test-配置文件打包出来文件有hash值,加上下面的配置,打包就和pro一致NODE_ENV='production'NODE_ENV只能设置production和development两个参数开发环境是development,生产环境都是produ......
  • 计算机毕业设计springboot+vue学生档案学籍信息管理系统java
    本文所设计的学籍系统的设计与实现拥有前端和后端,前端使用Vue.js框架和创建,后端使用Springboot框架创建,开发语言采用Java,使用Mysql数据库对后台数据进行存储。将IDEA作为主要的开发工具。接着进行系统的需求分析、功能设计、数据库设计,最后进行编码实现。技术栈ide工具:IDEA......
  • 1915springboot VUE 宠物寄养平台系统开发mysql数据库web结构java编程计算机网页源码m
    一、源码特点 springbootVUE宠物寄养平台系统是一套完善的完整信息管理类型系统,结合springboot框架和VUE完成本系统,对理解JSPjava编程开发语言有帮助系统采用springboot框架(MVC模式开发),系统具有完整的源代码和数据库,系统主要采用B/S模式开发。springbootVUE宠物寄养......
  • vue2.2——cdn如何使用插槽
    <mynav><h1slot="h1">我是具名插槽</h1><h2slot="h2">我没有命名</h2></mynav>letcp_template={mynav:{template:`<divstyle="color:red;"><......
  • vue学习笔记(一)
    本文章是在B站学习vue中整理的简单笔记,课程是ant编程的vue入门(如果涉及商业等因素,请我联系删除文章)使用的脚手架是CLI,非Vite.创建项目安装npminstall-g@vue/cli创建项目vuecreate[项目名称]选择manually 选择babelroutervuexlinter 选择3.x 选择Y 选择第......
  • Vue2批量全局注册组件
    创建一个文件(例如global-components.js),并在其中实现批量注册组件的逻辑。//src/global-components.jsimportVuefrom'vue';//自动导入components目录下的所有.vue文件constrequireComponent=require.context(//组件目录的相对路径'./components',//是......