组件数据与vuejs中的道具 [英] component data vs its props in vuejs
问题描述
官方文档说组件中可能有数据
和 props
选项。
The official documentation says that there could be a data
and a props
option in a component.
对我来说,这似乎是一种过度的功能。
For me it seems a sort of excessive functionality.
为什么我的组件中既需要属性又需要数据?他们的目标是什么?
Why do I need both properties and data in my component? Which goals they are aimed?
推荐答案
属性意味着从父组件传播和管理,而数据是组件内部状态(该组件负责)。
Properties are meant to be propagated and managed from parent components, while data is the component internal state (which the component is responsible for).
据我所知,这个概念取自React,效果非常好。
https://github.com/uberVU/react-guide/ blob / master / props-vs-state.md
This concept is taken from React as far as i know, and it works pretty well. https://github.com/uberVU/react-guide/blob/master/props-vs-state.md
这篇关于组件数据与vuejs中的道具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!