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

Loading animation implemented with CSS3

Achieve results Implementation Code <h1>123...

4 ways to view processes in LINUX (summary)

A process is a program code that runs in the CPU ...

CSS3 to achieve floating cloud animation

Operation effect html <head> <meta chars...

JavaScript to achieve simple tab bar switching case

This article shares the specific code for JavaScr...

A complete guide to some uncommon but useful CSS attribute operations

1. Custom text selection ::selection { background...

How to install Composer in Linux

1. Download the installation script - composer-se...

MySQL's conceptual understanding of various locks

Optimistic Locking Optimistic locking is mostly i...

How to choose and use PNG, JPG, and GIF as web image formats

So which one of these formats, GIF, PNG, and JPG,...

Detailed explanation of the cache implementation principle of Vue computed

Table of contents Initialize computed Dependency ...

Solve the Linux Tensorflow2.0 installation problem

conda update conda pip install tf-nightly-gpu-2.0...

Detailed explanation of CSS float property

1. What is floating? Floating, as the name sugges...

td width problem when td cells are merged

In the following example, when the width of the td...