uni determines whether you are currently in the app or the WeChat official account

You can use methods in uni.app uni.getSystemInfoto 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('当前在微信公众号中')
        }
      },
    });
  },
};

Guess you like

Origin blog.csdn.net/m0_38007556/article/details/133130394