Vue-render函數(shù)的三個(gè)參數(shù)

render函數(shù)的第一個(gè)參數(shù)

  1. 第一個(gè)參數(shù)必選.
  2. 可選類型
    • string:html標(biāo)簽
    • object:一個(gè)含有數(shù)據(jù)選項(xiàng)的對(duì)象
    • function:返回一個(gè)含有數(shù)據(jù)選項(xiàng)的對(duì)象
    Vue.component('child', {
        props: ['level'],
        render: function (createElement) {
            //string:html標(biāo)簽
            return createElement('h1')
            //object:一個(gè)含有數(shù)據(jù)選項(xiàng)的對(duì)象
            return createElement({
                template: '<div>談笑風(fēng)生</div>'
            })
            //function:返回一個(gè)含有數(shù)據(jù)選項(xiàng)的對(duì)象
            var domFun = function () {
                return {
                    template: `<div>談笑風(fēng)生</div>`
                }
            }
            return createElement(domFun())
        }
    })

render函數(shù)的第二個(gè)參數(shù)

  1. 第二個(gè)參數(shù)可選
  2. 第二個(gè)參數(shù)是數(shù)據(jù)對(duì)象。只能是object
    • class
    • style
    • attrs
    • domProps
    Vue.component('child', {
        props: ['level'],
        render: function (createElement) {
            return createElement('div', {
                class: {
                    foo: true,
                    baz: false
                },
                style: {
                    height: '34px',
                    background: 'orange',
                    fontSize: '16px'
                },
                //正常的html特性(除了class和style)
                attrs: {
                    id: 'foo',
                    title: 'baz'
                },
                //用來(lái)寫原生的DOM屬性
                domProps: {
                    innerHTML: '<span style="color:blue;font-size:24px">江心比心</span>'
                }
            })
        }
    })

render函數(shù)的第三個(gè)參數(shù)-代表子節(jié)點(diǎn)

  1. 第三個(gè)參數(shù)可選
  2. String|Array
    Vue.component('child', {
        props: ['level'],
        render: function (createElement) {
            return createElement('div', [
                createElement('h1', '我是大標(biāo)題'),
                createElement('h2', '我是二標(biāo)題'),
                createElement('h3', '我是三標(biāo)題')
            ])
        }
    })
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容