Vue.use()是什么?
生活随笔
收集整理的這篇文章主要介紹了
Vue.use()是什么?
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
2.在 Loading.vue 中定義一個(gè)組件
<template><div class="loading-box">Loading...</div> </template>3.在 index.js 中 引入 Loading.vue ,并導(dǎo)出
// 引入組件 import LoadingComponent from './loading.vue' // 定義 Loading 對(duì)象 const Loading={// install 是默認(rèn)的方法。當(dāng)外界在 use 這個(gè)組件的時(shí)候,就會(huì)調(diào)用本身的 install 方法,同時(shí)傳一個(gè) Vue 這個(gè)類的參數(shù)。install:function(Vue){Vue.component('Loading',LoadingComponent)} } // 導(dǎo)出 export default Loading4.在 main.js 中引入 loading 文件下的 index
// 其中'./components/loading/index' 的 /index 可以不寫,webpack會(huì)自動(dòng)找到并加載 index 。如果是其他的名字就需要寫上。 import Loading from './components/loading/index' // 這時(shí)需要 use(Loading),如果不寫 Vue.use()的話,瀏覽器會(huì)報(bào)錯(cuò),大家可以試一下 Vue.use(Loading)5.在App.vue里面寫入定義好的組件標(biāo)簽 <Loading></Loading>
<template><div id="app"><h1>vue-loading</h1><Loading></Loading></div> </template>總結(jié)
以上是生活随笔為你收集整理的Vue.use()是什么?的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 植物大战僵尸微信网名80个
- 下一篇: Vue.config.productio