Detailed explanation of Vue mixin

Detailed explanation of Vue mixin

insert image description here

Local Mixin

<template>
  <div>
    <h2 @click="showName">Student name: {{name}}</h2>
    <h2>Student gender: {{sex}}</h2>
  </div>
</template>

<script>
  //Introduce a mixed import {
    hunhe,hunhe2
  } from '../mixin'
  export default {
    name: 'Student',
    data() {
      return {
        name: 'Zhang San',
        sex: 'male'
      }
    },
    mixins: [hunhe,hunhe2]
  }

</script>

export const hunhe = {
    methods: {
        showName() {
            alert(this.name)
        }
    }
}

export const hunhe2 = {
    data() {
        return {
            x: 100,
            y: 200
        }
    }

}

Global Mixins

import { hunhe, hunhe2 } from './mixin'
Vue.mixin(hunhe)
Vue.mixin(hunhe2)

insert image description here

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:
  • A brief discussion on how Vue3 Composition API replaces Vue Mixins
  • How to use mixins in Vue
  • Detailed explanation of Vue mixin usage and option merging
  • Web project development VUE mixing and inheritance principle
  • Vue detailed explanation of mixins usage
  • How to use Vue3 mixin

<<:  CSS3 uses scale() and rotate() to achieve zooming and rotation

>>:  Blog Design Web Design Debut

Recommend

Several ways to encapsulate axios in Vue

Table of contents Basic Edition Step 1: Configure...

Detailed explanation of table return and index coverage examples in MySQL

Table of contents Index Type Index structure Nonc...

Using System.Drawing.Common in Linux/Docker

Preface After the project is migrated to .net cor...

How to store text and pictures in MySQL

Large Text Data Types in Oracle Clob long text ty...

A brief discussion on the solution of Tomcat garbled code and port occupation

Tomcat server is a free and open source Web appli...

Vue uses ECharts to implement line charts and pie charts

When developing a backend management project, it ...

How to try to add sticky effect to your CSS

Written in front I don’t know who first discovere...

Summary of Commonly Used MySQL Commands in Linux Operating System

Here are some common MySQL commands for you: -- S...

Use shell script to install python3.8 environment in CentOS7 (recommended)

One-click execution To install Python 3.8 in a vi...

Vue routing lazy loading details

Table of contents 1. What is lazy loading of rout...

Zabbix redis automatic port discovery script returns json format

When we perform automatic discovery, there is alw...

36 principles of MySQL database development (summary)

Preface These principles are summarized from actu...

Detailed installation history of Ubuntu 20.04 LTS

This article records the creation of a USB boot d...

web.config (IIS) and .htaccess (Apache) configuration

xml <?xml version="1.0" encoding=&qu...

Vue front-end development auxiliary function state management detailed example

Table of contents mapState mapGetters mapMutation...