1、vue2中 在vue2中我们可以直接在package.json中添加代码,获取环境只需要 process.env 获取到,运行的时候,会有三个选项,执行某一个即可。 "uni-app": { "scripts": { "dev": { "title": "微信小程序——开发版", "env": { "name": "dev", "UNI_PLATFORM": "mp-weixin",
if(process.env.VUE_APP_PLATFORM==='app-plus'){constdeviceInfo=plus.device;console.log("设备信息: ",deviceInfo);}else{console.error("当前平台不支持设备检测。");} 1. 2. 3. 4. 5. 6. 确保你在process.env.VUE_APP_PLATFORM检测上配置准确。如果在H5平台上运行该代码,可能会出现设备检测不成功...
$ npm install uni-simple-router uni-read-pages uni-read-pages的作用是:读取uniapp的pages.json,作为router的配置,把pages.json中的路由配置转换成vue-router配置的形式。 二、配置与初始化 1、根目录新建 vue.config.js 文件,写入以下内容: //vue.config.js const TransformPages = require('uni-read-pages...
//src/router/index.jsimport {RouterMount,createRouter}from'uni-simple-router';constrouter =createRouter({ platform: process.env.VUE_APP_PLATFORM, routes: [...ROUTES] });//全局路由前置守卫router.beforeEach((to,from, next) =>{ next(); });//全局路由后置守卫router.afterEach((to,from) =>...
exportdefault{onLoad(){// H5 禁止滚动if(process.env.VUE_APP_PLATFORM==='h5'){document.body.style.overflow='hidden';}// 小程序禁止滚动(需结合 CSS)uni.setStorageSync('disableScroll',true);},onUnload(){if(process.env.VUE_APP_PLATFORM==='h5'){document.body.style.overflow='';}uni.remove...
const router = createRouter({ platform: process.env.VUE_APP_PLATFORM, routes:[{ path:`/class/:id(\\d+).html`, component: Home }] }) URL表现 http://localhost:5174/#/class/6.html 静态路径格式 router.js const router = createRouter({ platform: process.env.VUE_APP_PLATFORM, route...
*/constrouter = createRouter({platform: process.env.VUE_APP_PLATFORM,routeNotFound:(to)=>{return{name:`404`} },routes:[ {path:`/login`,name:`login`,component:Login }, {path:`/404`,name:`404`,component:NotFound404 } ] })exportdefaultrouter ...
platform: process.env.VUE_APP_PLATFORM, routes: [...ROUTES] }); //全局路由前置守卫 router.beforeEach(async (to, from, next) => { next(); }); // 全局路由后置守卫 router.afterEach((to, from) => { console.log('跳转结束')
process.env.UNI_PLATFORM变量: Uni-app 提供了一个名为process.env.UNI_PLATFORM的全局变量,它表示当前的运行平台。通过判断该变量的值来实现条件编译。 例如,在代码中使用#ifdef和#endif来包裹需要根据平台不同而执行的代码块: <template><view><!-- #ifdef MP -->小程序端<!-- #endif --><!-- #...
platform: process.env.VUE_APP_PLATFORM, routes: [...ROUTES] }); //全局路由前置守卫 router.beforeEach((to, from, next) => { next(); }); // 全局路由后置守卫 router.afterEach((to, from) => { console.log('跳转结束') }) export { ...