在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/HTML/ 關(guān)于vue框架中的createElement方法的第二個(gè)參數(shù)

關(guān)于vue框架中的createElement方法的第二個(gè)參數(shù)

想請(qǐng)教一下,vue 框架中createElement方法的第二個(gè)參數(shù)具體作用是啥,看了官網(wǎng)的文檔后對(duì)這一參數(shù)的用法感到還是比較困惑。

clipboard.png

當(dāng)我自己敲了個(gè)組件試了下后,發(fā)現(xiàn)當(dāng)把第二個(gè)參數(shù)設(shè)置為這樣后,會(huì)對(duì)渲染出來(lái)的組件跟節(jié)點(diǎn)增加style,class等屬性?

import Vue from 'vue'

export default Vue.component('testCreateElement', {
    render: function (createElement) {
        return createElement({
            template: `
                <div @click="clickHandler">
                    <h1>This component is created by render function :):):)</h1>
                    <p>
                        {{statusNum}}
                    </p>
                    <h2>My name is: {{name}}</h2>
                    <h2>My age is: {{age}}</h2>
                    <slot></slot>
                </div>
            `,
            props: ['testProp1', 'testProp2'],
            data: function () {
                return {
                    statusNum: Math.random() * 10000
                }
            },
            methods: {
                clickHandler: function () {
                    this.$data.statusNum = Math.random() * 1000
                }
            }
        }, {
            // 和`v-bind:class`一樣的 API
            'class': {
                foo: true,
                bar: false
            },
            // 和`v-bind:style`一樣的 API
            style: {
                color: 'red',
                fontSize: '14px'
            },
            // 正常的 HTML 特性
            attrs: {
                id: 'foo'
            },
            // 組件 props
            props: {
                myProp: 'bar'
            }
        }, [
            '先寫(xiě)一些文字',
            createElement('h1', '一則頭條')
        ])
    }
})
{
    // 和`v-bind:class`一樣的 API
    'class': {
        foo: true,
        bar: false
    },
    // 和`v-bind:style`一樣的 API
    style: {
        color: 'red',
        fontSize: '14px'
    }
    ...
}

clipboard.png

回答
編輯回答
夏木

第二個(gè)參數(shù)是屬性的設(shè)置。比如:class, style, attrs等

2018年5月31日 10:15