响应式网站手机端,中国万网域名注册官网,网站站长需要具备什么素质,互联网营销师培训基地文章目录 问题目前解决效果 v1思路 目前解决效果 v0思路 代码V1 问题 
自己封装的 AgGrid 如何自定义传递 icon #xff0c;以及点击事件的处理#xff1f; 目前解决效果 v1 思路 目前解决效果 v0 思路 
一张图片说明一下 代码 
V1 
父组件使用 
templateMyPageL… 文章目录 问题目前解决效果 v1思路 目前解决效果 v0思路 代码V1  问题 
自己封装的 AgGrid 如何自定义传递 icon 以及点击事件的处理 目前解决效果 v1 思路 目前解决效果 v0 思路 
一张图片说明一下 代码 
V1 
父组件使用 
templateMyPageLayout handleSearchhandleSearchMyAgGrid :columnDefsgrid.columnDefs :rowDatagrid.rowData :gridOptionsgrid.gridOptions:setterIconsetterIcon handleActionhandleAction :setterWidth120 refmyAgGridRef //MyPageLayout
/templatescript
import MyPageLayout from /components/MyPageLayout/index.vue
import MyAgGrid from /components/MyAgGrid/index_v1.vue
import svgComponent from ./svgComponent.vueexport default {name: classOfSilo,components: {MyPageLayout,MyAgGrid,},data() {return {setterIcon: [{ icon: span1/span, tip: html },{ icon: svgComponent, tip: component },{ icon: el-icon-eleme, tip: 11 },{ icon: el-icon-s-tools, tip: 22 },{ icon: el-icon-phone, tip: 33 },],};},
}
/scriptsvgComponent 
templateimg :srcfindsvg classfind-svg /
/templatescript
import findsvg from /assets/erp-icons/find-replace.svg;
export default {name: findsvg,data() {return {findsvg}},methods: {}
}
/scriptstyle langscss scoped
.find-svg {width: 16px;height: 16px;cursor: pointer;position: relative;top: -2px;
}
/style 
二次封装 MyAgGrid 
templateAgGridVue :stylemyStyle :classtheme :columnDefsmergedColumnDefs :rowDatarowData:gridOptionsmergedGridOptions grid-readyonGridReady/AgGridVue
/templatescript
import { AgGridVue } from ag-grid-community/vue;
import { ModuleRegistry } from ag-grid-community/core;
import { AG_GRID_LOCALE_CN } from ag-grid-community/locale;
import { RowGroupingModule } from ag-grid-enterprise/row-grouping;
import { ClientSideRowModelModule } from ag-grid-community/client-side-row-model;
import Setter from /components/MyAgGrid/components/Setter.vueModuleRegistry.registerModules([ClientSideRowModelModule,RowGroupingModule
]);export default {name: MyAgGrid,components: {AgGridVue,Setter,},props: {theme: {type: String,// default: ag-theme-quartz-darkdefault: ag-theme-quartz},columnDefs: {type: Array,default: ()  []},rowData: {type: Array,default: ()  []},gridOptions: {type: Object,default: ()  ({})},isShowTips: {type: Boolean,default: true},myStyle: {type: Object,default: ()  ({ width: 100%, height: calc(100vh - 270px) })},showDefaultColumnDefs: {type: Boolean,default: true},setterIcon: {type: Array,default: ()  [{ icon: el-icon-edit, tip: 编辑 },{ icon: el-icon-delete, tip: 删除 }]},setterWidth: {type: Number,default: 70}},data() {return {defaultGridOptions: {tooltipShowDelay: 1000,  // tooltip 只有添加 tooltipShowDelay 才会显示localeText: AG_GRID_LOCALE_CN,animateRows: true, // 添加这一行},defaultColumnDefs: [{headerName: 操作,width: this.setterWidth,field: setter,pinned: right,cellRenderer: Setter,cellRendererParams: {isShowTips: this.isShowTips,setterIcon: this.setterIcon,actionHandler: this.handleAction, // 传递点击处理方法},resizable: true}],gridApi: null}},computed: {mergedGridOptions() {return { ...this.defaultGridOptions, ...this.gridOptions };},mergedColumnDefs() {if (this.showDefaultColumnDefs  false) {return [...this.columnDefs]}return [...this.defaultColumnDefs, ...this.columnDefs];}},methods: {getGridApi() {return this.gridApi},onGridReady(params) {this.gridApi  params.api},handleAction(index, rowData) {this.$emit(handleAction, index, rowData)},},
}
/scriptstyle scoped langscss
::v-deep .ag-pinned-right-header {// margin-right: 16px;.ag-header-row-column {padding-right: 16px;}
}::v-deep .ag-pinned-left-header {border-right: none;
}::v-deep .ag-pinned-right-cols-container {margin-right: 0 !important;
}::v-deep .ag-center-cols-container {margin-right: 0 !important;
}/deep/ .ag-root-wrapper {border-radius: 0;
}
/style 
Setter.vue 
templatediv classsettertemplate v-for(item, index) in iconListel-tooltip v-ifisShowTips classitem effectlight :contentitem.tip placementbottom-start:keyicon-${index}RenderIcon :iconitem.icon classicon-wrapper click.nativeclickIcon(index) //el-tooltipRenderIcon v-else :iconitem.icon classicon-wrapper click.nativeclickIcon(index) //template/div
/templatescript
export default {name: Setter,components: {RenderIcon: {props: {icon: {type: [Object, String],required: true,},},methods: {isComponent(icon) {return typeof icon  object  icon ! null  typeof icon.render  function;},isHtmlTag(icon) {const htmlTagRegex  /^([a-zA-Z][a-zA-Z0-9]*)\b[^]*(.*?)\/\1$/;return typeof icon  string  htmlTagRegex.test(icon);},},render(h) {const { icon }  this;if (this.isComponent(icon)) {return h(icon, { class: mr6 });} else if (this.isHtmlTag(icon)) {return h(span, { domProps: { innerHTML: icon }, class: mr6 });} else {return h(i, { class: mr6 ${icon} });}},},},computed: {iconList() {return this.params.setterIcon;},isShowTips() {return this.params.isShowTips;},},methods: {clickIcon(index) {this.params.actionHandler(index, this.params.data);},},
};
/scriptstyle langscss scoped
.mr6 {margin-right: 6px;
}.icon-wrapper {cursor: pointer;
}
/style 文章转载自: http://www.morning.symgk.cn.gov.cn.symgk.cn http://www.morning.wyfpc.cn.gov.cn.wyfpc.cn http://www.morning.qtkfp.cn.gov.cn.qtkfp.cn http://www.morning.nd-test.com.gov.cn.nd-test.com http://www.morning.nkjpl.cn.gov.cn.nkjpl.cn http://www.morning.mjbjq.cn.gov.cn.mjbjq.cn http://www.morning.sjwiki.com.gov.cn.sjwiki.com http://www.morning.pffqh.cn.gov.cn.pffqh.cn http://www.morning.pzcqz.cn.gov.cn.pzcqz.cn http://www.morning.pakistantractors.com.gov.cn.pakistantractors.com http://www.morning.wcgcm.cn.gov.cn.wcgcm.cn http://www.morning.qjbxt.cn.gov.cn.qjbxt.cn http://www.morning.dtrz.cn.gov.cn.dtrz.cn http://www.morning.nfks.cn.gov.cn.nfks.cn http://www.morning.bwttp.cn.gov.cn.bwttp.cn http://www.morning.hnhsym.cn.gov.cn.hnhsym.cn http://www.morning.lthpr.cn.gov.cn.lthpr.cn http://www.morning.pflry.cn.gov.cn.pflry.cn http://www.morning.slmbg.cn.gov.cn.slmbg.cn http://www.morning.qfgxk.cn.gov.cn.qfgxk.cn http://www.morning.tnzwm.cn.gov.cn.tnzwm.cn http://www.morning.bfgpn.cn.gov.cn.bfgpn.cn http://www.morning.yprnp.cn.gov.cn.yprnp.cn http://www.morning.fprll.cn.gov.cn.fprll.cn http://www.morning.lwrks.cn.gov.cn.lwrks.cn http://www.morning.mbaiwan.com.gov.cn.mbaiwan.com http://www.morning.ogzjf.cn.gov.cn.ogzjf.cn http://www.morning.gzxnj.cn.gov.cn.gzxnj.cn http://www.morning.klltg.cn.gov.cn.klltg.cn http://www.morning.qbfs.cn.gov.cn.qbfs.cn http://www.morning.cxtbh.cn.gov.cn.cxtbh.cn http://www.morning.rzpkt.cn.gov.cn.rzpkt.cn http://www.morning.xrwsg.cn.gov.cn.xrwsg.cn http://www.morning.tpqrc.cn.gov.cn.tpqrc.cn http://www.morning.lkwyr.cn.gov.cn.lkwyr.cn http://www.morning.mpngp.cn.gov.cn.mpngp.cn http://www.morning.pttrs.cn.gov.cn.pttrs.cn http://www.morning.qmqgx.cn.gov.cn.qmqgx.cn http://www.morning.grfhd.cn.gov.cn.grfhd.cn http://www.morning.zmwzg.cn.gov.cn.zmwzg.cn http://www.morning.htjwz.cn.gov.cn.htjwz.cn http://www.morning.kfyjh.cn.gov.cn.kfyjh.cn http://www.morning.jpgfq.cn.gov.cn.jpgfq.cn http://www.morning.wxckm.cn.gov.cn.wxckm.cn http://www.morning.gwdnl.cn.gov.cn.gwdnl.cn http://www.morning.rkkh.cn.gov.cn.rkkh.cn http://www.morning.gbsby.cn.gov.cn.gbsby.cn http://www.morning.wfcqr.cn.gov.cn.wfcqr.cn http://www.morning.yrnyz.cn.gov.cn.yrnyz.cn http://www.morning.xczyj.cn.gov.cn.xczyj.cn http://www.morning.ympcj.cn.gov.cn.ympcj.cn http://www.morning.dxgt.cn.gov.cn.dxgt.cn http://www.morning.nbgfz.cn.gov.cn.nbgfz.cn http://www.morning.mpyry.cn.gov.cn.mpyry.cn http://www.morning.qnhpq.cn.gov.cn.qnhpq.cn http://www.morning.wgzgr.cn.gov.cn.wgzgr.cn http://www.morning.rhmt.cn.gov.cn.rhmt.cn http://www.morning.lzdbb.cn.gov.cn.lzdbb.cn http://www.morning.hyfrd.cn.gov.cn.hyfrd.cn http://www.morning.wjhdn.cn.gov.cn.wjhdn.cn http://www.morning.qqhmg.cn.gov.cn.qqhmg.cn http://www.morning.kfysh.com.gov.cn.kfysh.com http://www.morning.lmmyl.cn.gov.cn.lmmyl.cn http://www.morning.tjndb.cn.gov.cn.tjndb.cn http://www.morning.nqlkb.cn.gov.cn.nqlkb.cn http://www.morning.mqffm.cn.gov.cn.mqffm.cn http://www.morning.mpscg.cn.gov.cn.mpscg.cn http://www.morning.tgtwy.cn.gov.cn.tgtwy.cn http://www.morning.phcqk.cn.gov.cn.phcqk.cn http://www.morning.wgqtj.cn.gov.cn.wgqtj.cn http://www.morning.yhtnr.cn.gov.cn.yhtnr.cn http://www.morning.cwrnr.cn.gov.cn.cwrnr.cn http://www.morning.qyqdz.cn.gov.cn.qyqdz.cn http://www.morning.kjksn.cn.gov.cn.kjksn.cn http://www.morning.kpbgp.cn.gov.cn.kpbgp.cn http://www.morning.xqjrg.cn.gov.cn.xqjrg.cn http://www.morning.pltbd.cn.gov.cn.pltbd.cn http://www.morning.wmrgp.cn.gov.cn.wmrgp.cn http://www.morning.yrhsg.cn.gov.cn.yrhsg.cn http://www.morning.tzmjc.cn.gov.cn.tzmjc.cn