Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

component data vs its props in vuejs

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?

like image 242
pepper Avatar asked Feb 22 '16 07:02

pepper


People also ask

What does props mean in Vue?

What are Props in Vue. js? “Props” is a special keyword which stands for properties. It can be registered on a component to pass data from a parent component to one of its children components. This is a lot easier compared to using state management libraries like vuex for Vue.

What are props in Vue components?

What are props? In Vue, props (or properties), are the way that we pass data from a parent component down to it's child components. When we build our applications out of components, we end up building a data structure called a tree.

Can I use props in data Vue?

Using props in VueAfter you have set up the props, you can then use it inside your component as though the data was defined inside the same component. This means you can set up method calls and easily access this.

What are the 3 parts of a component in Vue?

Components in Vue are composed of three parts; a template (which is like HTML), styles and JavaScript. These can be split into multiple files or the same .


1 Answers

Properties are meant to be propagated and managed from parent components, while data is the component internal state (which the component is responsible for).

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

like image 94
TiagoLr Avatar answered Oct 06 '22 03:10

TiagoLr