Vue3 – 从父组件继承的属性

huangapple go评论57阅读模式
英文:

Vue3 - Inherited property from parent

问题

Is there a way that I can propagate a readonly property to all nested components without needing to declare a 'readonly:boolean' property in every component?

英文:

I'm creating some components, is there a way that I can propagate a reaonly property to all nested(with nested components) without needing to declare a 'readonly:boolean' property in every component?

答案1

得分: 1

Use provide('name', var) in your parent component and const var = inject('name') in your descendant components: https://vuejs.org/guide/components/provide-inject.html

英文:

Use provide('name', var) in your parent component and
const var = inject('name') in your descendant components:
https://vuejs.org/guide/components/provide-inject.html

huangapple
  • 本文由 发表于 2023年5月26日 01:09:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76334749.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定