Re-learning mixins in vue

Description

  • Mixing is an object, and then mixing this object into a certain component

  • The content in data and methods is repeated, and components are used first

  • Life cycle function, first use mixin

  • Can modify priority

  • Define the mixed-in object

 const myMixin = {
    
    
     data(){
    
    
         return {
    
    
             a:1
         }
     }
  }
  • Use mixed components

    data(){
    
    
        return {
    
    
            a:2
        },
    mixins: [myMixin],
  • Modify priority
  app.config.optionMergeStrategies.number = (mixinVal,appValue) => {
    
    
    return mixinVal || appValue;
  }

Guess you like

Origin blog.csdn.net/qq_45549336/article/details/111016820