如何在Vue Js 3中直接将props传递给嵌套组件?

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

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

huangapple
  • 本文由 发表于 2023年3月12日 13:24:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/75711207.html
匿名

发表评论

匿名网友

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

确定