vue如何判断当前访问的设备是PC还是H5

一、定义

export const _isMobile = () => {
    let flag = navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)
    return flag;
}

二、使用

 if (_isMobile()) {
      alert("手机端");
      this.$router.push('/m_index');
    } else {
      alert("pc端");
      this.$router.push('/pc_index');
    }

猜你喜欢

转载自blog.csdn.net/L_yupeng/article/details/125723878
今日推荐