在uni.app中可以使用uni.getSystemInfo
方法来获取系统信息,然后判断是否在App中或在微信公众号中。
export default {
data() {
return {
};
},
created() {
uni.getSystemInfo({
success: (res) => {
// 判断是否在App中
if (res.platform === 'ios' || res.platform === 'android') {
console.log('当前在app中')
}
// 判断是否在微信公众号中
if (res.platform === 'devtools' && res.appId === 'tourist') {
console.log('当前在微信公众号中')
}
},
});
},
};