uni 判断当前是否在app还是在微信公众号

在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('当前在微信公众号中')
        }
      },
    });
  },
};

猜你喜欢

转载自blog.csdn.net/m0_38007556/article/details/133130394