uniapp 设置全局无需引入的变量 和 方法

import App from './App.vue'
import * as Pinia from 'pinia';

import { createSSRApp } from 'vue'

export function createApp() {
	const app = createSSRApp(App)

	app.use(uviewPlus)
	app.use(Pinia.createPinia());

	// 在js里直接调用 不要写$Platform  app可能会报错
	uni.wPlatform = uni.getSystemInfoSync().platform
	uni.wStatusBarHeight = uni.getSystemInfoSync().statusBarHeight
	// 在html模板里直接调用
	app.config.globalProperties.wPlatform = uni.getSystemInfoSync().platform
	app.config.globalProperties.wStatusBarHeight = uni.getSystemInfoSync().statusBarHeight


	// 兼容写法, 否则真机可能会找不到pinia
	return {
		Pinia,
		app
	}
}

posted on 2023-11-28 21:16  完美前端  阅读(228)  评论(0)    收藏  举报

导航