1. Component OrganizationTypically an application is organized as a nested component tree: For example, we may have components such as headers, sidebars, and content areas, each of which may contain other components such as navigation links and blog posts. In order to be used in templates, these components must first be registered so that So far, our components are all registered globally through Vue.component('my-component-name', { // ... options ... }) Globally registered components can be used in any newly created 2. Component nameWhen registering a component, we always need to give it a name. For example, we have seen this when registering globally: Vue.component('my-component-name', { /* ... */ }) The component name is the first parameter of 2.1 Component NamingThere are two ways to define component names:
Hyphen separated names Vue.component('my-component-name', { /* ... */ }) When defining a component using (hyphen separated names), for example: Capitalize the first letter Vue.component('MyComponentName', { /* ... */ }) When defining a component using (capitalized first letter), you can use either naming convention when referencing the custom element. That is, both
3. Global RegistrationGlobal registration is to use Vue.component to create components: Java Vue.component('my-component-name', { // ... options... }) These components are registered globally. This means that they can be used in the template of any newly created for example: <div id="app"> <component-a></component-a> <component-b></component-b> <component-c></component-c> </div> Vue.component('component-a', { /* ... */ }) Vue.component('component-b', { /* ... */ }) Vue.component('component-c', { /* ... */ }) new Vue({ el: '#app' }) However, global registration is not often used in actual projects. 4. Partial Registration Global registration is often suboptimal. For example, if you use a build system like In these cases, you can define the component via a plain let ComponentA = { template: `<p>hello</p>` } let ComponentB = { template: `<p>world</p>` } Then define the components you want to use in the new Vue({ el: '#app', components: 'component-a': ComponentA, 'component-b': ComponentB } }) For each Of course, in the actual development process, we use the module system to register more components, which will be introduced later. This is the end of this article about the organizational structure of Vue components and the details of component registration. For more relevant Vue component organizational structure and component registration content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: MySQL string splitting example (string extraction without separator)
>>: Docker+selenium method to realize automatic health reporting
Today, let’s get straight to the point and talk a...
system: VMTOOLs Download: Link: https://pan.baidu...
This article records the installation tutorial of...
Table of contents 1. Introduction 2. Understand t...
Install boost There are many ways to call C/C++ f...
Table of contents What is Proxy Mode? Introducing...
Simple function: Click the plug-in icon in the up...
Let's take a look at the dynamic splicing of ...
Copy code The code is as follows: <form action...
Caused by: java.sql.SQLException: Incorrect strin...
Preface This article introduces the use of vue-ro...
The overall architecture of NGINX is characterize...
How to implement the paging function of MyBatis i...
I have installed various images under virtual mac...
All consecutive spaces or blank lines (newlines) ...