Spublic.js
let Vue
 
const testFun = (e) =>{
    console.log(e,"OK")
}

function install(_Vue) {
     Vue = _Vue
     Vue.mixin({
         beforeCreate(){
             if(this.$options.Song){
                 Vue.prototype.$testFun=testFun
             }
         }
     })

}

export default {install}
Copy the code
main.js
import Vue from 'vue'
import Song from './utils/sPublic';
Vue.use(Song)

new Vue({
  Song,
  render: h => h(App),
}).$mount('#app')
Copy the code
.vue
BeforeCreate (){this.$testFun(' call ')}Copy the code