English | 简体中文
A vite plug-in to solve the asynchronous problem between onlaunch and onload in uniapp+vue3.2
pnpm add vite-uni-await-onlaunch -D
or
npm i vite-uni-await-onlaunch -D
- Config plugin in vite.config.ts. In this way, the required functions can be introduced as needed
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)
}
})],
})
params | required | type | default | explain |
---|---|---|---|---|
fn | yes | () => Promise<any> |
methods to be executed first on the current page, such as login, etc |
|
pagesRE | no | RegExp |
/src/pages | page regularity to insert fn |
triggerMethods | no | string[] |
['onLoad', 'onShow'] |
The inserted life cycle array has a decreasing priority. Only one is inserted. For example, if the page has onload and Onshow, it is only executed in advance in onload.fn |
MIT