Vue.use使用方法
a.vueコンポーネント
<template>
<div>{{msg}}</div>
</template>
<script>
export default {
data() {
return {
msg: 'aaa '
}
}
}
</script>
//alert.js共通メソッド
import aaa from './components/a'
export default {
install(Vue, options) {
Vue.prototype.$alert = function (){
alert('my is self fun');
};
Vue.prototype.$userName = function (){
alert('my name is self userName');
};
Vue.yjl = function() {
alert('yjl')
};
Vue.component('Loading', aaa);
}
}
//main.js入口
Window.Vue = Vue;// window
import alert from './alert'
Vue.use(alert);
//home.vueコンポーネント呼び出し
<template>
<div class="home">
<button @click="addmain"> </button>
<Loading></Loading>
</div>
</template>
<script>
export default {
name: 'home',
methods:{
addmain(){
console.log(Vue);
Vue.yjl();//
this.$alert();//
this.$userName();
}
}
}
</script>