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
This article uses examples to illustrate the prin...
How to change the image hyperlink when the mouse p...
The specific code of the sliding button made with...
Say it in advance On a whim, I want to know what ...
Through the brief introduction in the previous tw...
What is a web page? The page displayed after the ...
In normal development, we usually use convex roun...
Table of contents Method 1: set: It is not a data...
offset Offset is the offset. Using the offset ser...
Preface I have been summarizing my front-end know...
First, let’s take an example: There is a type fie...
Check what is installed in mysql rpm -qa | grep -...
Table of contents 1. isPrototypeOf() Example 1, O...
Table of contents Problem Description Method 1 (b...
Table of contents 1. Introduction to platform bus...