Vue.use使用方法


  • 主にVueプロトタイプにカスタムを追加する方法と変数
  • を説明する.
  • は、UIコンポーネントライブラリを導入するように、独自のプラグインまたはライブラリ(elementUI、axiosなど)
  • を導入することもできる.
  • prototype、install、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>