1.基于install(app实例对象, 选项参数)方法定义
//Ly-plugin.ts 文件
import type {App} from 'vue' // 引入vue内的App 类型
// 自定义v3 plugin
export const lyonPlugin = {
install(app:App, params:any) {
app.config.globalProperties.lyon = 'xxxx'
console.log('打印plugin参数')
console.log(params) // 打印: {pluginParams: 'Lyon'} ( plugin参数)
// app -- vue 实例 伪代码 app 实例相关均可挂入 同app 一样,统一管理
// app.component() // 挂组件
// app.directive() // 挂指令
// app.mixin() // 挂混入
// app.config() // 挂配置
}
}
// 使用plugin
// app.use(lyonPlugin)
2. plugin 的使用 通过use() 同router pinia Vant 插件一样
import { lyonPlugin } from './plugins/Ly-plugin'
app.use(lyonPlugin, {pluginParams: 'Lyon'}).mount('#app')