1. 编写loading组件(components/Loading/index.vue)
<template>
<div>loading</div>
</template>
<script>
export default {
name: 'loading'
}
</script>
2.注册为全局组件 (components/Loading/index.js)
import loading from './index.vue'
const loadingOp= {
install: (Vue) => {
Vue.component('loading', loading)
}
}
export default loadingOp
3.定义组件库(components/index.js)
import Model from './Model'
import Loading from './Loading'
export default {
Model,
Loading
}
4.开启全局使用此组件 (main.js)
import componetList from './components'
const { Model, Loading } = componetList
Vue.use(Model).use(Loading)
5. 使用组件
<template>
<loading></loading>
</template>
网友评论