解决uniapp+vue3.2中onlaunch和onload之间异步问题的vite插件
pnpm add vite-uni-await-onlaunch -D
or
npm i vite-uni-await-onlaunch -D
import { defineConfig, Plugin } from 'vite'
import vue from '@vitejs/plugin-vue'
import AwaitOnlaunch from 'vite-uni-await-onlaunch'
export default defineConfig({
plugins: [vue(), AwaitOnlaunch({
fn: () => {
// your code
// return a promise
return Promise.resolve(1)
}
})],
})
参数 | 必填 | 类型 | 默认值 | 说明 |
---|---|---|---|---|
fn | yes | () => Promise<any> |
无 | 当前页面要先执行的方法,如登录等 |
pagesRE | no | RegExp |
src下的pages目录 | 需要插入fn的页面正则,默认src下的pages目录 |
triggerMethods | no | string[] |
['onLoad', 'onShow'] |
插入的生命周期数组,优先级递减,只插入一个,如页面有onLoad和onShow,只在onLoad中提前执行fn |
MIT