官方說(shuō)明
https://developers.weixin.qq.com/miniprogram/dev/devtools/pc-dev.html
小程序如何判斷是 PC 平臺(tái)?
通過(guò) getSystemInfo 官方接口(platform 是 windows)
通過(guò) UA(PC UA 包含 MiniProgramEnv/Windows)文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-764923.html
App.vue
<script>
export default {
onLaunch: function () {
console.warn(
"當(dāng)前組件僅支持 uni_modules 目錄結(jié)構(gòu) ,請(qǐng)升級(jí) HBuilderX 到 3.1.0 版本以上!"
);
console.log("App Launch", uni.getSystemInfoSync().platform);
uni.setStorageSync("platform", uni.getSystemInfoSync().platform);
uni.setStorageSync(
"windowWidth",
wx.getStorageSync("devices").windowWidth
);
uni.setStorageSync(
"windowHeight",
wx.getStorageSync("devices").windowHeight
);
},
onLoad() {},
onShow: function () {
},
onHide: function () {
},
};
</script>
<style lang="scss">
/*每個(gè)頁(yè)面公共css */
@import "@/uni_modules/uni-scss/index.scss";
// 設(shè)置整個(gè)項(xiàng)目的背景色
page {
background-color: #f5f5f5;
}
</style>
判斷是否是pc端的函數(shù)(如果寬度足夠也視為pc端)
/** 是否是pc端 */
function isPC() {
if (["windows", "mac"].some((v) => v === wx.getStorageSync("platform"))) {
return true;
}
if (Number(wx.getStorageSync("windowWidth")) > 1000) {
return true;
}
return false;
}
同時(shí)值得注意的是,微信開發(fā)者工具的platform
屬性是devtools
,只能體驗(yàn)版中進(jìn)行測(cè)試真實(shí)的platform
屬性文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-764923.html
到了這里,關(guān)于uniapp開發(fā)小程序-如何判斷小程序是在手機(jī)端還是pc端打開的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!