Detailed explanation of the relationship between Vue and VueComponent

Detailed explanation of the relationship between Vue and VueComponent

The following case reviews the knowledge points of the prototype chain we learned before

       // Define a constructor function Demo() {
            this.a = 1
            this.b = 2
        }
        //Create a Demo instance object const d = new Demo()
        console.log(Demo.prototype); //Display prototype properties console.log(d.__proto__); //Implicit prototype properties console.log(Demo.prototype === d.__proto__); //true
        //The programmer operates the prototype object by displaying the prototype attributes and appending an x ​​attribute with a value of 99
        Demo.prototype.x = 99
        console.log('@',d.__proto__.x); 

Analyze VueComponent according to the following component

<body>
    <div id="root">
         <school></school>
    </div>
    <script>
        Vue.config.productionTip = false
        //Define the school component const school = Vue.extend({
            name: 'school',
            template: `
              <div>
                <h2>School name: {{name}}</h2>
                <h2>School address: {{address}}</h2>
              </div>
            `,
            data() {
                return {
                    name: 'Shang Silicon Valley',
                    address: 'Beijing'
                }
            }   
        })
        //Create Vue
        new Vue({
            el:'#root',
            components:{
                school,
            }
        })
    </script>
</body> 

1. The school component is essentially a constructor called VueComponent , and it is not defined by the programmer, but generated by Vue.extend

2. We only need to write <school/> or <school</school>, and Vue will help us create an instance object of the school component when parsing; that is, Vue helps us execute: new VueComponent(options)

3. Special note: Every time Vue.extend is called, a new VueComponent is returned

4. About this pointing:

  • In component configuration: data functions, functions in methods , functions in watch , functions in computed , their this are all VueComponent instance objects
  • In new Vue(options) configuration: data functions, functions in methods , functions in watch , functions in computed , their this are all Vue instance objects

5. VueComponent instance object, hereinafter referred to as vc ---- component instance object

Key Points

  • An important built-in relationship: VueComponent.prototype._proto_===Vue.prototype
  • Why is this relationship necessary: ​​to allow the component instance object vc to access the properties and methods on the Vue prototype

Summarize

This article ends here. I hope it can be helpful to you. I also hope you can pay more attention to more content on 123WORDPRESS.COM!

You may also be interested in:
  • Vue built-in component component--dynamically render component operations through the is attribute
  • Vue.component property description
  • vue dynamic component
  • Vue components dynamic components detailed explanation
  • Solve the component tag rendering problem of Vue

<<:  Interaction in web design: A brief discussion on paging issues

>>:  A brief discussion on the difference between MYSQL primary key constraint and unique constraint

Recommend

Viewing and analyzing MySQL execution status

When you feel that there is a problem with MySQL ...

Detailed explanation of virtual DOM in Vue source code analysis

Why do we need virtual dom? Virtual DOM is design...

js realizes packaging multiple pictures into zip

Table of contents 1. Import files 2. HTML page 3....

A brief discussion on several specifications of JS front-end modularization

Table of contents Preface The value of front-end ...

How to use Vue to develop public account web pages

Table of contents Project Background start Create...

5 Reasons Why Responsive Web Design Isn’t Worth It

This article is from Tom Ewer's Managewp blog,...

Docker installs Elasticsearch7.6 cluster and sets password

Starting from Elasticsearch 6.8, free users are a...

Implementation of Docker deployment of MySQL cluster

Disadvantages of single-node database Large-scale...

6 ways to view the port numbers occupied by Linux processes

For Linux system administrators, it is crucial to...

How to create a Django project + connect to MySQL

1: django-admin.py startproject project name 2: c...

Several ways to switch between Vue Tab and cache pages

Table of contents 1. How to switch 2. Dynamically...

Native js to achieve seamless carousel effect

Native js realizes the carousel effect (seamless ...

Detailed explanation of Docker Swarm concepts and usage

Docker Swarm is a container cluster management se...

Next.js Getting Started Tutorial

Table of contents Introduction Create a Next.js p...