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
The time of VM Ware virtual machine centos is inc...
This article example shares the specific code of ...
Table of contents Combining lookahead and lookbeh...
Table of contents 1. Preface 2. Find two pop-up c...
Contemporary web visual design has gone through th...
Achieve results Implementation Code html <div ...
Table of contents 1. Prototype mode Example 1 Exa...
Add the jvm.options file to the elasticsearch con...
What is volume? Volume means capacity in English,...
Table of contents 1. Global Guard 1. Global front...
version: centos==7.2 jdk==1.8 confluence==6.15.4 ...
This article will explain the composition of the ...
Table of contents 1. Overview 2. Django Project 3...
System: Ubuntu 16.04LTS 1\Download mysql-5.7.18-l...
Windows cmd telnet format: telnet ip port case: t...