官方说明
https://developers.weixin.qq.com/miniprogram/dev/devtools/pc-dev.html
小程序如何判断是 PC 平台?
通过uni.getSystemInfoSync().platform
api获取平台值,如果值是windows
或者mac
说明是pc端
App.vue
<script>
export default {
onLaunch: function () {
uni.setStorageSync("platform", uni.getSystemInfoSync().platform);
uni.setStorageSync("devices", uni.getSystemInfoSync());
uni.setStorageSync(
"windowWidth",
uni.getSystemInfoSync().windowWidth
);
uni.setStorageSync(
"windowHeight",
uni.getSystemInfoSync().windowHeight
);
},
};
</script>
判断是否是pc端的函数(如果宽度足够也视为pc端,根据实际需求自行调整)
/** 是否是pc端 */
function isPC() {
if (["windows", "mac"].some((v) => v === uni.getStorageSync("platform"))) {
return true;
}
if (Number(uni.getStorageSync("windowWidth")) > 1000) {
return true;
}
return false;
}