僅3.4.10+版本以上才支持,如果您的hbuilderX版本不是這個版本的需要先升級一下版本?hbuilderx下載
選擇3.4.11及以上版本
const type = uni.getSystemInfoSync().uniPlatform
console.log(type) // app
uniPlatform?可取值如下:文章來源:http://www.zghlxwxcb.cn/news/detail-511664.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-511664.html
/**枚舉EPlatform*/
export enum EPlatform {
/**App*/
AppPlus = 'APP-PLUS',
/**App nvue*/
AppPlusNvue = 'APP-PLUS-NVUE',
/**H5*/
H5 = 'H5',
/**微信小程序*/
MpWeixin = 'MP-WEIXIN',
/**支付寶小程序*/
MpAlipay = 'MP-ALIPAY',
/**百度小程序*/
MpBaidu = 'MP-BAIDU',
/**字節(jié)跳動小程序*/
MpToutiao = 'MP-TOUTIAO',
/**QQ小程序*/
MpQq = 'MP-QQ',
/**360小程序*/
Mp360 = 'MP-360',
/**微信小程序/支付寶小程序/百度小程序/字節(jié)跳動小程序/QQ小程序/360小程序*/
Mp = 'MP',
/**快應(yīng)用通用(包含聯(lián)盟、華為)*/
QuickappWebview = 'quickapp-webview',
/**快應(yīng)用聯(lián)盟*/
QuickappWebviewUnion = 'quickapp-webview-union',
/**快應(yīng)用華為*/
QuickappWebviewHuawei = 'quickapp-webview-huawei',
}
/**使用條件編譯獲取平臺信息*/
export function ifDefPlatform(): EPlatform {
let platform: EPlatform
//#ifdef APP-PLUS
platform = EPlatform.AppPlus;
//#endif
//#ifdef APP-PLUS-NVUE
platform = EPlatform.AppPlusNvue;
//#endif
//#ifdef H5
platform = EPlatform.H5;
//#endif
//#ifdef MP-WEIXIN
platform = EPlatform.MpWeixin;
//#endif
//#ifdef MP-ALIPAY
platform = EPlatform.MpAlipay;
//#endif
//#ifdef MP-BAIDU
platform = EPlatform.MpBaidu;
//#endif
//#ifdef MP-TOUTIAO
platform = EPlatform.MpToutiao;
//#endif
//#ifdef MP-QQ
platform = EPlatform.MpQq;
//#endif
//#ifdef MP-360
platform = EPlatform.Mp360;
//#endif
//#ifdef MP
platform = EPlatform.Mp;
//#endif
//#ifdef quickapp-webview
platform = EPlatform.QuickappWebview;
//#endif
//#ifdef quickapp-webview-union
platform = EPlatform.QuickappWebviewUnion;
//#endif
//#ifdef quickapp-webview-huawei
platform = EPlatform.QuickappWebviewHuawei;
//#endif
return platform
}
/**平臺類型*/
export const Platform: EPlatform = ifDefPlatform()
/**默認導(dǎo)出平臺類型*/
export default Platform
/**App*/
export const isAppPlus = Platform == EPlatform.AppPlus
/**App nvue*/
export const isAppPlusNvue = Platform == EPlatform.AppPlusNvue
/**H5*/
export const isH5 = Platform == EPlatform.H5
/**微信小程序*/
export const isMpWeixin = Platform == EPlatform.MpWeixin
/**支付寶小程序*/
export const isMpAlipay = Platform == EPlatform.MpAlipay
/**百度小程序*/
export const isMpBaidu = Platform == EPlatform.MpBaidu
/**字節(jié)跳動小程序*/
export const isMpToutiao = Platform == EPlatform.MpToutiao
/**QQ小程序*/
export const isMpQq = Platform == EPlatform.MpQq
/**360小程序*/
export const isMp360 = Platform == EPlatform.Mp360
/**微信小程序/支付寶小程序/百度小程序/字節(jié)跳動小程序/QQ小程序/360小程序*/
export const isMp = Platform == EPlatform.Mp
/**快應(yīng)用通用(包含聯(lián)盟、華為)*/
export const isQuickappWebview = Platform == EPlatform.QuickappWebview
/**快應(yīng)用聯(lián)盟*/
export const isQuickappWebviewUnion = Platform == EPlatform.QuickappWebviewUnion
/**快應(yīng)用華為*/
export const isQuickappWebviewHuawei = Platform == EPlatform.QuickappWebviewHuawei
/**是否開發(fā)環(huán)境*/
export const isDevelopment = process.env.NODE_ENV == 'development'
/**是否線上環(huán)境*/
export const isProduction = process.env.NODE_ENV == 'production'
/**抖音小程序*/
export const isMpDouyinApp = uni.getSystemInfoSync().appName == 'Douyin'
/**頭條小程序*/
export const isMpToutiaoApp = uni.getSystemInfoSync().appName == 'Toutiao'
到了這里,關(guān)于uniapp判斷當(dāng)前運行環(huán)境 app h5 微信小程序的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!