You can use methods in uni.app uni.getSystemInfo
to obtain system information, and then determine whether it is in the App or in the WeChat official account.
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('当前在微信公众号中')
}
},
});
},
};