Web project development VUE mixing and inheritance principle

Web project development VUE mixing and inheritance principle

Mixin

  • Extract the function codes that are reused in multiple vue files into a single js file and call it where it is needed.
  • Define an object in a js file. In the object, you can write data, methods, components and other codes that can be defined in <script> in the vue file.

Mixin Note (duplicate name)

  • If there is a duplication between the data variable name in the component and the data variable name in the mixin, the component takes precedence;
  • If there are duplicate names of methods, computed, and wath in a component and methods, computed, and wath in a mixin, the component takes precedence;
  • When the life hook function in the component and the life hook function in the mixin have the same name, both will be executed, but the hook function in the component will be executed first;

Local Mixin

insert image description here

Global Mixins

Definition and global registration

insert image description here

Call

insert image description here

inherit

  • Note: Multiple inheritance is not suitable here, as multiple inheritance problems will occur more frequently.
  • In addition to inheriting .vue files, extends can also use objects in js files like mixin.
  • The HTML in the template in the extends inheritance.vue file cannot be inherited

insert image description here

Difference between mixin and inheritance

  • Let's first look at the definition in the official document. In fact, both can be understood as inheritance;
  • Mixins receive an array of objects (which can be understood as multiple inheritance);
  • What extends receives is an object or a function (which can be understood as single inheritance).
  • Note: If a component uses both inheritance and mixins, if there is a duplicate name between the two, the mixin will override the inheritance.

The above is the detailed content of the mixing and inheritance principles of VUE in web project development. For more information about web development, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • A brief discussion on how Vue3 Composition API replaces Vue Mixins
  • Detailed explanation of Vue mixin
  • How to use mixins in Vue
  • Detailed explanation of Vue mixin usage and option merging
  • Vue detailed explanation of mixins usage
  • How to use Vue3 mixin

<<:  Using NTP for Time Synchronization in Ubuntu

>>:  Optimized record of using IN data volume in Mysql

Recommend

Detailed explanation of Javascript Echarts air quality map effect

We need to first combine the air quality data wit...

A brief discussion on using virtual lists to optimize tables in el-table

Table of contents Preface Solution Specific imple...

Ubuntu 20.04 how to modify the IP address example

illustrate: Today, when continuing the last offic...

MySQL database connection exception summary (worth collecting)

I found a strange problem when deploying the proj...

MySQL 5.5.27 winx64 installation and configuration method graphic tutorial

1. Installation Package MYSQL service download ad...

Introduction to the usage of common XHTML tags

There are many tags in XHTML, but only a few are ...

XHTML Basic 1.1, a mobile web markup language recommended by W3C

W3C recently released two standards, namely "...

MySQL 8.0.19 installation and configuration method graphic tutorial

This article records the installation and configu...

Front-end state management (Part 2)

Table of contents 1. Redux 1.1. Store (librarian)...

HTML table tag tutorial (13): internal border style attributes RULES

RULES can be used to control the style of the int...

js implements shopping cart addition and subtraction and price calculation

This article example shares the specific code of ...