英文:
How to pass props to the nested component directly in Vue Js 3?
问题
想象一个场景,App.vue >> Todo.vue >> Popup.vue >> Field.vue
。我怎样可以直接从 Todo.vue
传递属性到 Field.vue
组件?或者说在更复杂的嵌套组件结构中。
我知道我们可以使用存储(stores),但我想知道 Vue.js 3 是否有类似 Svelte JS 中的 "Context" 的 API?
期待回复。
英文:
Imagine a scenario, App.vue >> Todo.vue >> Popup.vue >> Field.vue
. How can I pass props from Todo.vue
directly to Field.vue
component? Or let's say in a more complex nested component structure.
I know we can use stores but I would like to know if Vue js 3 have api something like "Context" in Svelte JS?
Looking forward.
答案1
得分: 2
以下是您要翻译的内容:
Precisely the scenario you describe is explained in the docs
In short:
Todo.vue
Field.vue
Be sure to check your the article in the docs I've provided
英文:
Precisely the scenario you describe is explained in the docs
In short:
Todo.vue
provide('keyForYourProvidedProp', valueForYourProvidedProp);
Field.vue
const message = inject('keyForYourProvidedProp');
Be sure to check your the article in the docs I've provided
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论