插件:插件 (Plugins) 是一种能为 Vue 添加全局功能的工具代码(也可以注册组件)
https://cn.vuejs.org/guide/reusability/plugins.html
全局注册组件:https://cn.vuejs.org/guide/components/registration.html
javascript
import { App } from 'vue'
import table from './src/index.vue' //引入组件
// 让这个组件可以通过use的形式使用
export default {
install(app: App) {
app.component('m-table', table) //插件为注册组件
}
}
javascript
import { App } from 'vue'
// 每一个引入的都是一个插件
import chooseArea from './chooseArea'
import chooseIcon from './chooseIcon'
import trend from './trend'
import notification from './notification'
import list from './list'
import menu from './menu'
import chooseTime from './chooseTime'
import chooseDate from './chooseDate'
import progress from './progress'
import chooseCity from './chooseCity'
import form from './form'
import modalForm from './modalForm'
import table from './table'
import calendar from './calendar'
const components = [
chooseArea,
chooseIcon,
trend,
notification,
list,
menu,
chooseTime,
chooseDate,
chooseCity,
progress,
form,
modalForm,
table,
calendar
]
export default {
install(app: App) {
// 循环中使用插件
components.map(item => {
app.use(item)
})
}
}
最后可以在main.js
javascript
import mUI from './components'
app.use(use(mUI))