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

Example of how to mosaic an image using js

This article mainly introduces an example of how ...

Summary of five commands to check swap space in Linux

Preface Two types of swap space can be created un...

Layui implements the login interface verification code

This article example shares the specific code of ...

Detailed analysis of binlog_format mode and configuration in MySQL

There are three main ways of MySQL replication: S...

Specific use of Node.js package manager npm

Table of contents Purpose npm init and package.js...

MySQL 5.7.23 version installation tutorial and configuration method

It took me three hours to install MySQL myself. E...

11 Linux KDE applications you didn't know about

KDE Abbreviation for Kool Desktop Environment. A ...

Examples of correct judgment methods for data types in JS

Table of contents Preface Can typeof correctly de...

Detailed explanation of the general steps for SQL statement optimization

Preface This article mainly shares with you the g...

Download MySQL 5.7 and detailed installation diagram for MySql on Mac

1. Enter the following address in the browser htt...