鍍金池/ 問答/HTML/ vuejs&iview使用render函數(shù)渲染自定義組件不成功,如何解決

vuejs&iview使用render函數(shù)渲染自定義組件不成功,如何解決?

iview官網(wǎng)代碼:

 render: (h, params) => {
                            return h('div', [
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            this.show(params.index)
                                        }
                                    }
                                }, 'View'),
                                h('Button', {
                                    props: {
                                        type: 'error',
                                        size: 'small'
                                    },
                                    on: {
                                        click: () => {
                                            this.remove(params.index)
                                        }
                                    }
                                }, 'Delete')
                            ]);
                        }
                    }

我注冊了一個(gè)組件:QiDropdown,并引入到components里面,但是渲染報(bào)錯(cuò):

import QiDropdown from '@/components/QiDropdown'

export default {
    components:{
        QiDropdown
    },
...
render:(h,params)=>{
                        if(params.row.callout){
                            return h('div',params.row.callout);
                        }else{
                            return h('QiDropdown')
                        }
                    }
...

QiDropdown.vue組件代碼:

<style lang="postcss" scoped>
.qi-dropdown{

}
</style>
<template>
<section class="qi-dropdown">
    <Dropdown>
        <a href="javascript:void(0)">
            下拉菜單
            <Icon type="arrow-down-b"></Icon>
        </a>
        <DropdownMenu slot="list">
            <DropdownItem>驢打滾</DropdownItem>
            <DropdownItem>炸醬面</DropdownItem>
            <DropdownItem disabled>豆汁兒</DropdownItem>
            <DropdownItem>冰糖葫蘆</DropdownItem>
            <DropdownItem divided>北京烤鴨</DropdownItem>
        </DropdownMenu>
    </Dropdown>
</section>
</template>
<script>
export default {
    data(){
        return{
            
        }
    }
}
</script>

clipboard.png

回答
編輯回答
硬扛

找到正解了:
https://segmentfault.com/q/10...

這里已經(jīng)是你的自定義組件(標(biāo)簽了,不需要用引號(hào)括起來了)

return h('div', [

h(TimeClock, {
  props: {
    hour: params.row.startTime.sTimeHour,
    minute: params.row.startTime.sTimeMinute
  }
})

]);

2017年7月6日 12:23
編輯回答
詆毀你
import QiDropdown from '@/components/QiDropdown'

export default {
render:(h,params)=>{
                        if(params.row.callout){
                            return h('div',params.row.callout);
                        }else{
                            // 直接使用導(dǎo)入的組件
                            return h(QiDropdown)
                        }
                    }
2017年4月28日 20:58