render 函数渲染表格的当前数据列使用

实例1:

columns7: [
// 实例1:代码段
{
title: '编号',
align: 'center',
width: 90,
key: 'No',
render: (h, params) => {
return h('p', {
style: 'color:#2D8CF0;font-size:14px;cursor: pointer;',
on: {
'click': () => {
this.GotoPage(params.row)
}
}
}, params.row.No)
}
},
// 实例2代码段: 未写成组件前
{
title: '个数',
align: 'center',
width: 100,
key: 'popupArr',
render: (h, params) => {
let arrData = params.row.SumArr
let rowData = []
// 弹窗内容处理
let popupCon = []
if (params.row.popupArr.length){
popupCon = [
h('p', {}, `个数: ${params.row.popupArr.length}`),
h('p', {}, [
h('span', {class: 'pop-span1'}, '金额'),
h('span', {class: 'pop-span3'}, '号码')
])
]
params.row.popupArr.map(items => {
let money = null
money = h('p', {}, [
h('span', {class: 'pop-span1'}, `¥${this.numberComma(Number(items.Amount).toFixed(2))}`),
h('span', {class: 'pop-span2'}, `${items.Number}`)
])
popupCon.push(money)
})
}
// 外层内容
arrData.map((item, index) => {
// 单元格行的内容
// on-popper-show 为监听事件,鼠标移上去请求接口拿数据展示在浮窗中
let rowsC = null
let tooltip = []
        // Tooltip
tooltip[0] = h('Tooltip', {
props: {placement: 'left', 'delay': 700, 'max-width': '600'},
on: {
'on-popper-show': () => {
this.PopperShow(h, params)
}
}
}, [
h('p', {style: 'min-width: 70px;'}, item.Count),
h('div', {slot: 'content'}, popupCon)
])
// 小单元格外层框
if (index + 1 === arrData.length) {
rowsC = h('p', {
style: 'padding:0 0 0 0;height:40px;line-height:40px;'
}, tooltip)
} else {
rowsC = h('p', {
style: 'padding:0 0 0 0;height:40px;line-height:40px;border-bottom: 1px solid #E8EAEC;'
}, tooltip)
}
rowData.push(rowsC)
})
return h('div', {class: 'countCol'}, rowData)
}
},
] // 方法
methods: {
 PopperShow (h, params) {
// 请求接口已封装
this.$store.dispatch('GetInvoicedInfo', params.row.Id).then((res) => {
     if (res.Result) {
       this.$nextTick(() => {
       params.row.popupArr = res.Data
       this.$forceUpdate()
     })
   }
})
  }
}

  

实例2:

render: Tooltip 动态获取浮窗数据的实例

以上代码我们可以优化下,将浮窗Tooltip写成公共组件的方式,在render中引入该模板组件:

columns7: [
{
title: '个数',
align: 'center',
width: 100,
key: 'popupArr',
render: (h, params) => {
let arrData = params.row.SumArr
let rowData = []// 外层内容
arrData.map((item, index) => {
// 单元格行的内容
// on-popper-show 为监听事件,鼠标移上去请求接口拿数据展示在浮窗中
let rowsC = null
let tooltip = []
        // Tooltip
          tooltip[0] = h(vInfoTooltip, {
            props: {
              placement: 'left',
              rowId: params.row.Id,
              dataNo: item.No
            },
            slot: 'content'
          }, [
            h('p', {
              style: 'min-width: 70px;',
              slot: 'infoTooltip'
            }, [
              h('span', {
                style: 'color: rgb(45, 140, 240);cursor: pointer;font-size:14px;',
                slot: 'content'
              }, item.Count)
            ])
          ])
        // 小单元格外层框
if (index + 1 === arrData.length) {
rowsC = h('p', {
style: 'padding:0 0 0 0;height:40px;line-height:40px;'
}, tooltip)
} else {
rowsC = h('p', {
style: 'padding:0 0 0 0;height:40px;line-height:40px;border-bottom: 1px solid #E8EAEC;'
}, tooltip)
}
rowData.push(rowsC)
})
return h('div', {class: 'countCol'}, rowData)
}
},
]

InfoTooltip.vue

<template>
<div class="InfoTooltip">
<Tooltip :placement="placement" :delay="700" @on-popper-show="PopperShow" @on-popper-hide="PopperHide" max-width="600">
<slot name="infoTooltip"></slot> <!-- 该内容即 鼠标移上去的内容 -->
<div class="demo-InfoList" slot="content"> <!-- 该div内的内容即为 浮窗的内容 -->
<p>个数: {{InfoList.length}}</p>
<p>
<span class="pop-span1">金额</span>
<span class="pop-span2">号码</span>
<span class="pop-span3">状态</span>
</p>
<p v-for="(items, index) in InfoList" :key="index">
<span class="pop-span1">¥{{numberComma(Number(items.Amount).toFixed(2))}}</span>
<span class="pop-span2">{{items.Number}}</span>
<span class="pop-span3">{{items.Status}}</span>
</p>
</div>
</Tooltip>
</div>
</template>
<script>
export default {
name: 'InfoTooltip',
components: {
},
data () {
return {
InfoList: []
}
},
props: {
rowId: String,
dataNo: String,
placement: {
type: String,
default: 'right-start'
}
},
created () {
},
computed: {
},
methods: {
GetPopupArrFn (arrData, dataNo) {
let obj = {}
arrData.map(function (item) {
let timeKey = item.InvoDate.split(' ')[0]
if (!obj[timeKey]) {
obj[timeKey] = []
}
obj[timeKey].push(item)
})
return obj[dataNo]
},
PopperHide () {
},
PopperShow () {
this.$store.dispatch('GetInvoicedInfo', this.rowId).then((res) => {
if (res.Result) {
this.$nextTick(() => {
this.InfoList = this.GetPopupArrFn(res.Data, this.dataNo)
})
}
})
}
}
}
</script> <style scoped lang="less">
.demo-InfoList {
display: inline-table;
p {
float: left;
width: 100%;
line-height: 22px;
}
.pop-span1 {
width:120px;
display:inline-block;
}
.pop-span2{
width:200px;
display:inline-block;
}
.pop-span3{
width:80px;
display:inline-block;
text-align:center;
}
}
</style>

最后效果即如图:

鼠标移入小单元格时,动态请求浮窗内容

render 函数渲染表格的当前数据列使用的更多相关文章

  1. 使用render函数渲染组件

    使用render函数渲染组件:https://www.jianshu.com/p/27ec4467a66b

  2. 在vue中结合render函数渲染指定的组件到容器中

    1.demo 项目结构: index.html <!DOCTYPE html> <html> <head> <title>标题</title> ...

  3. iview,用render函数渲染

    <Table border :columns="discountColumns" :data="discountData.rows"></Ta ...

  4. 使用Python的Flask框架,结合Highchart,动态渲染图表(Ajax 请求数据接口)

    参考链接:https://www.highcharts.com.cn/docs/ajax 参考链接中的示例代码是使用php写的,这里改用python写. 需要注意的地方: 1.接口返回的数据格式,这个 ...

  5. render方法渲染组件和在webpack中导入vue

    使用component注册的组件div容器里可以放多个,但是使用render的只能放一个 <div id="app"> <p>我可以放两个</p> ...

  6. iview table表中使用render函数props传值出现问题

    使用iview中的table表格时避免不了使用render函数渲染自定义内容,或者渲染组件.但是在正常使用时出现了props传值无法识别, 按照官网介绍使用props如下: render: (h, p ...

  7. vue入门:(底层渲染实现render函数、实例生命周期)

    vue实例渲染的底层实现 vue实例生命周期 一.vue实例渲染的底层实现 1.1实例挂载 在vue中实例挂载有两种方法:第一种在实例化vue时以el属性实现,第二种是通过vue.$mount()方法 ...

  8. 超全table功能Datatables使用的填坑之旅--1: 无法渲染表格数据: ajax调用了参数 : success

    问题:Datatables: 无法渲染表格数据 原因:datatables的ajax 传了"success":function(){},导致无法渲染数据. ajax 删掉" ...

  9. oracle数据库查询日期sql语句(范例)、向已经建好的表格中添加一列属性并向该列添加数值、删除某一列的数据(一整列)

    先列上我的数据库表格: c_date(Date格式)     date_type(String格式) 2011-01-01                   0 2012-03-07         ...

随机推荐

  1. Spring课程 Spring入门篇 7-1 Aspect介绍及PointCut注解应用

    本节主要是理论型: 关键看下节实操. 这个其实只要理解一点:使用AspectJ进行Spring AOP 编程,其实就是使用了JAVA注解的风格进行配置和使用. 不像之前讲的那样在配置文件中配置使用.

  2. 网站大于10M的视频不能播放

    IIS配置的网站,添加了几个mp4视频,有个可以正常播放,有的却不加载不出来,提示错误: net::ERR_CONNECTION_ABORTED 网上有文章说是由于安全狗bug导致,下载安装一个补丁覆 ...

  3. Html5的新特性总结

    新加语义化标签: HTML5其实是关于图像,位置,存储,速度的优化和改进 图像: 到目前为止,基本上想要直接在网页上进行绘图还是不能轻易完成的,即使是几何图形也不可以.在浏览器当中直接能跟图片的交互操 ...

  4. side Effect

    副作用 side Effect 副作用是在计算结果的过程中,系统状态的一种变化,或者与外部世界进行的可观察的交互. 副作用可能包含,但不限于: 1.更改文件系统 2.往数据库里插入数据 3.发送一个h ...

  5. Python入门-生成器和生成器表达式

    昨天我们说了迭代器,那么和今天说的生成器是什么关系呢? 一.生成器 什么是生成器?说白了生成器的本质就是迭代器. 在Python中中有三种方式来获取生成器. 1.通过生成器函数 2.通过各种推导式来实 ...

  6. ERROR:Tried to register widget id ==basemapGalleryDiv but that id is already registered解决办法

    在ArcGIS Server开发中,遇到DIV已经被注册的情况,不能对原DIV内容进行更新.这里需要调用Dojo的destroyRecursive()方法,逐个销毁该Widget下的子元素及其后代元素 ...

  7. [小北De编程手记] : Lesson 04 - Selenium For C# 之 API 上

    这一部分,我准备向大家介绍Selenium WebDriver的常用API,学习这部分内容需要大家最好有一些简单的HTML相关知识,本文主要涉及到以下内容: Selenium API:元素检查 Sel ...

  8. Fundmentals in Stream Computing

    Spark programs are structured on RDDs: they invole reading data from stable storage into the RDD for ...

  9. Java 之变量和常量(2)

    Java中的关键字: Java 语言中有一些具有特殊用途的词被称为关键字.关键字对 Java 的编译器有着特殊的意义,在程序中应用时一定要慎重哦!! Java 中常用关键字: 问:这么多,记不住啊.. ...

  10. 【Python之搜索引擎】(一)概述

    learning goal--search engine 1.Find datas - crawl 2.Index 3.page rank String操作 提取网络中的链接 Extracting a ...