| |
|
开发:
C++知识库
Java知识库
JavaScript
Python
PHP知识库
人工智能
区块链
大数据
移动开发
嵌入式
开发工具
数据结构与算法
开发测试
游戏开发
网络协议
系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程 数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁 |
-> JavaScript知识库 -> Vue 官方笔记--组件 -> 正文阅读 |
|
[JavaScript知识库]Vue 官方笔记--组件 |
中文版(英文浓缩)组件是什么?组件:具有预定义选项的实例
创建应用实例通过 createApp 函数创建创建了应用实例(application instance),它表明 Vue 应用的开始 这个应用实例未来会通过
这个应用实例用来注册一个全局信息,在整个 Vue 应用中的所有组件都可以使用这个全局信息
根组件根组件就是 应用实例 经过 mount() 函数挂载所返回的东西(如 传递给 createApp 函数的选项是用于配置根组件的,比如
当我们为我们的应用实例使用 应用实例调用方法(除了mount 方法)后,还是会返回一个应用实例(比如 app 是一个应用实例,调用 app.component( /* xxx */ ) 之后,还是会返回一个应用实例) 但是,mount 方法不会返回应用实例,而是会返回根组件实例 应用实例最终需要挂载到一个 DOM 元素中() 如 mount 内部是这样实现的
每个组件都会有自己的组件实例,比如
在应用中的组件实例都会共享根组件实例 我们可以在组件实例中添加用户自定义的属性,如 这些所有的自定义属性都可以在模板中使用,比如
英文原版what is the Component?component is an abstraction that allows us to build large-scale applications composed of small, self-contained, and often reusable components. component :instance with pre-defined options In Vue, a
But this would render the same text for every todo, which is not super interesting. We should be able to pass data from the parent scope into child components. Let’s modify the component definition to make it accept a prop
we have managed to separate our app into two smaller units, and the child is reasonably well-decoupled from the parent via the ??props interface. We can now further improve our In a large application, it is necessary to divide the whole app into components to make development manageable. We will talk a lot more about components later in the guide, but here’s an (imaginary) example of what an app’s template might look like with components:
Creating an Application InstanceEvery Vue application starts by creating a new
The application instance is used to register ‘globals’ that can then be used by components within that application. We’ll discuss that in detail later in the guide but as a quick example:
Most of the methods exposed by the The Root ComponentThe options passed to That component is used as the ? 🔰 starting ?point for rendering when we mount the application. An application needs to be mounted into a DOM element. For example, if we want to mount a Vue application into Unlike most of the application methods, Although not strictly associated with the MVVM pattern (opens new window), Vue’s design was partly inspired by it. As a convention, we often use the variable While all the examples on this page only need a single component, most real applications are organized into a tree of nested, reusable components. For example, a Todo application’s component tree might look like this:
Each component will have its own component instance, We’ll talk about the component system in detail later. For now, just be aware that the root component isn’t really any different from any other component. The configuration options are the same, as is the behavior of the corresponding component instance difference between an instance and an obejct ? Once you instantiate a class (using new), that instantiated thing becomes an object.
an object represents a set of instances while an instance is a certain, specific representation. Component Instance PropertiesEarlier in the guide we met
There are various other component options that add user-defined properties to the component instance, such as Vue also exposes some built-in properties via the component instance, such as Lifecycle HooksEach component instance goes through a series of initialization steps when it’s created - for example, it needs to set up data observation, compile the template, mount the instance to the DOM, and update the DOM when data changes. Along the way, it also runs functions called lifecycle hooks, giving users the opportunity to add their own code at specific stages. For example, the created hook can be used to run code after an instance is created:
There are also other hooks which will be called at different stages of the instance’s lifecycle, such as mounted, updated, and unmounted. All lifecycle hooks are called with their TIP Don’t use arrow functions (opens new window)on an options property or callback, such as |
|
JavaScript知识库 最新文章 |
ES6的相关知识点 |
react 函数式组件 & react其他一些总结 |
Vue基础超详细 |
前端JS也可以连点成线(Vue中运用 AntVG6) |
Vue事件处理的基本使用 |
Vue后台项目的记录 (一) |
前后端分离vue跨域,devServer配置proxy代理 |
TypeScript |
初识vuex |
vue项目安装包指令收集 |
|
上一篇文章 下一篇文章 查看所有文章 |
|
开发:
C++知识库
Java知识库
JavaScript
Python
PHP知识库
人工智能
区块链
大数据
移动开发
嵌入式
开发工具
数据结构与算法
开发测试
游戏开发
网络协议
系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程 数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁 |
360图书馆 购物 三丰科技 阅读网 日历 万年历 2025年3日历 | -2025/3/27 13:42:56- |
|
网站联系: qq:121756557 email:121756557@qq.com IT数码 |
|