如何理解Vue的非prop属性

案例:

<div id="app">
    <my-comp data-title="learn vue" class="mycls" style="color:red;"></my-comp>
</div>
<script>
    Vue.component('my-comp', {
        template: '<div>我是组件</div>'
    });
    new Vue({
        el: '#app'
    });
</script>

运行结果如图:

图片描述

说明:data-title,class,style就是非prop属性,无需定义相应的prop,这些属性都会被添加到组件的根元素上。

评论

暂无评论