vue组件的 Attribute 继承
<div id="hyy">
<compomenta :label='message' placeholder="test" def="message"></compomenta>
</div>
Vue.component("compomenta",{
props: ['label'],
template:'<input v-bind:value="label" def="haha">',
})
var test = new Vue({
el: "#hyy",
data: { //
stime:"",//开始时间
message:"label",
test:"lllll"
},
})
即与props无关的元素也会被继承到子组件上,class与style会合并,其他属性会覆盖
上方最后生成的html为
<input placeholder="test" def="message" value="label" >
Vue组件的Attribute继承与属性覆盖
这篇博客探讨了Vue组件中Attribute的继承机制。在示例中,父组件的属性如`placeholder`和`def`被传递并合并到子组件的`<input>`元素上,而`value`属性由于在子组件内定义为props,因此覆盖了父组件的同名Attribute。这展示了Vue中组件如何处理外部属性和内部props的关系,以及class和style的合并规则。
316

被折叠的 条评论
为什么被折叠?



