名词解释:

$attrs--继承所有的父组件属性(除了prop传递的属性、class 和 style )

inheritAttrs:默认值true,继承所有的父组件属性(除props的特定绑定)作为普通的HTML特性应用在子组件的根元素上,如果你不希望组件的根元素继承特性设置inheritAttrs: false,但是class属性会继承

主要用途

用在父组件传递数据给子组件或者孙组件

<body>

<div />'  //<base-input>元素中,除了class,label(proprs中已经有了)外,剩下placeholder  和 data-date-picker的属性以及属性值全部继承过来了
+' </label>'
,
mounted: function() {
console.log(this.$attrs);
}
})
const app = new Vue({
el: '#app',
data: {

}

});

</script>

</body>

 

渲染出来的结果:

<label class="username-input">
姓名
Enter your username
activated
<input placeholder="Enter your username" data-date-picker="activated">
</label>

 

如果把上面例子中的inheritAttrs: false去掉或者改为inheritAttrs: true,最终渲染为:

<label placeholder="Enter your username" data-date-picker="activated" class="username-input">
姓名
Enter your username
activated
<input placeholder="Enter your username" data-date-picker="activated">
</label>

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2023-03-08
  • 2021-09-15
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案