What is the difference between mixin and component in vue
The difference between mixin and component: After the component is referenced, it is equivalent to opening up a separate space in the parent component to perform corresponding operations based on the values from the parent component props. In essence, the two are still distinct. Relatively independent; after the component is introduced, mixins are equivalent to various attribute methods of the parent component that have been expanded, and the internal content of the component such as data and other methods, method and other attributes will be merged with the corresponding content of the parent component.
The operating environment of this tutorial: windows7 system, vue3 version, DELL G3 computer.
What is Mixin?
Mixins are a very flexible way to distribute reusable functionality in Vue components.
Mixed objects can contain arbitrary component options.
When a component uses a mixin object, all the options of the mixin object will be mixed into the options of the component itself. [Related recommendations: vuejs video tutorial, web front-end development]
The difference between mixin and components
After the component is referenced, it is equivalent to opening up a separate space in the parent component to perform corresponding operations based on the values from the parent component's props. In essence, the two are distinct and relatively independent.
After the component is introduced, mixins merge the internal content of the component such as data and other methods, method and other attributes with the corresponding content of the parent component. It is equivalent to that after the introduction, various property methods of the parent component have been expanded.
Simple component reference:
Parent component sub-component>>> Parent component sub-component
mixins:
Parent component Child component>>> new parent component
It’s a bit like registering a public method of vue that can be bound Used in multiple components or multiple Vue object instances. Another point is similar to registering a method in a prototype object. In an instance object, that is, a component or a Vue instance object, you can still define a method with the same function name to override it, which is a bit like a subclass and a parent class.
The difference between mixins and vuex
Mixins: You can define shared variables and use them in each component. After being introduced into the component, each variable are independent of each other, and value modifications will not affect each other in the component. If the object is the same, the component will overwrite mixins
vuex: used for state management. The variables defined in it can be used and modified in each component. After modifying the value of this variable in any component, other The value of this variable in the component will also be modified.
Use of mixins
1. First create a js file, such as elTableAdsorbent.js
1 2 3 4 5 6 7 8 9 10 11 12 |
|
or
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
2. Then introduce it into the vue page that requires this requirement and use
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
3. The hook functions with the same name will be merged into an array, so they will all be called. Additionally, the hooks of the mixin object will be called before the component's own hooks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
4. When the key names of two objects conflict, the key-value pair of the component object is taken.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
Application of mixins
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
(Learning video sharing: vuejs introductory tutorial, Programming Basics Video)
The above is the detailed content of What is the difference between mixin and component in vue. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

You can add a function to the Vue button by binding the button in the HTML template to a method. Define the method and write function logic in the Vue instance.

There are three ways to refer to JS files in Vue.js: directly specify the path using the <script> tag;; dynamic import using the mounted() lifecycle hook; and importing through the Vuex state management library.

The watch option in Vue.js allows developers to listen for changes in specific data. When the data changes, watch triggers a callback function to perform update views or other tasks. Its configuration options include immediate, which specifies whether to execute a callback immediately, and deep, which specifies whether to recursively listen to changes to objects or arrays.

Vue multi-page development is a way to build applications using the Vue.js framework, where the application is divided into separate pages: Code Maintenance: Splitting the application into multiple pages can make the code easier to manage and maintain. Modularity: Each page can be used as a separate module for easy reuse and replacement. Simple routing: Navigation between pages can be managed through simple routing configuration. SEO Optimization: Each page has its own URL, which helps SEO.

Vue.js has four methods to return to the previous page: $router.go(-1)$router.back() uses <router-link to="/" component window.history.back(), and the method selection depends on the scene.

There are three common methods for Vue.js to traverse arrays and objects: the v-for directive is used to traverse each element and render templates; the v-bind directive can be used with v-for to dynamically set attribute values for each element; and the .map method can convert array elements into new arrays.

The methods to implement the jump of a tag in Vue include: using the a tag in the HTML template to specify the href attribute. Use the router-link component of Vue routing. Use this.$router.push() method in JavaScript. Parameters can be passed through the query parameter and routes are configured in the router options for dynamic jumps.
