Article From:

Learning knowledge must be applied in the application scenario, so that we can really learn something and remember deeply. We will encounter similar things later.

1、stayassetsCreate a folder under the folderjsfile

// Create an object that needs to be mixedExport const mixinTest1 = {{Created () {This.hello ();},Methods: {Hello () {Console.log ('mixinTest1');}}};

2、Using the newly created mix in the component

import {mixinTest1} from './../assets/js/mixin';
export default {
    name: 'hello',
    data () {
        return {
            msg: 'Welcome to Your Vue.js App'

3、If the method defined in the component is the same as the method / attribute that is mixed into the object, the priority in the component is greater than that in the mixed object (the method will be called many times).

4、The abstract method can be defined in the mixed object, and the method must be rewritten by using the mixed component.

methods: {
    handlePlaylist() {
        throw new Error('component must implement handlePlaylist method')

  In fact, I copied others, I think it is not shameful, the important thing is that they can understand, do not care about other people’s views. It is good to be able to learn knowledge. Ha-ha

Link of this Article: Vue mixins application scene

Leave a Reply

Your email address will not be published. Required fields are marked *