vuejs 中的组件数据与它的 props [英] component data vs its props in vuejs

查看:22
本文介绍了vuejs 中的组件数据与它的 props的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

官方文档说组件中可以有dataprops选项.

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 中的组件数据与它的 props的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆