vuejs 技巧3 render 函数的各种写法史上最全

一:render 函数在表格中渲染组件:

like 组件: 

import like from '../../components/like'
 { title: '操作', key: 'action', width:80,align: 'center',
                        render: (h, params) => {
                            let arr=[
                                h(like, {
                                props: {
                                   item:params.row
                                },
                                on: {
                                    'like-this': (cb) => {
                                        this.likeThis(params.row,cb)
                                    },
                                    'unlike-this': (cb) => {
                                        this.unlikeThis(params.row,cb)
                                    },
                                }
                                }),
                            ];
                           
                           if(this.type==2 && params.row.childrenNum>0){
                               arr.push(h("img", {attrs:{src: "/images/rank/i-arrow.png"},style:{
                                    width: "0.12rem",
                                    height: "0.12rem",
                                    verticalAlign: "middle",
                                    marginLeft: "0.2rem"
                                }}))  
                           }
                           return h('div',arr);
                        }
                    }
posted @ 2020-01-13 19:20  石shi  阅读(408)  评论(0编辑  收藏  举报