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}
main.js
import Vue from 'vue'
import Song from './utils/sPublic';
Vue.use(Song)
new Vue({
Song,
render: h => h(App),
}).$mount('#app')
.vue 再组件内调用
beforeCreate(){
this.$testFun('调用')
}