一、前导:

今天被要求做vue在移动端输入PC端网址的时候自动判断并跳转到移动端页面,其实是比较懵逼的,因为没有做到。摸索了一番,做法如下,希望对懵逼的小伙伴有所帮助。

二、解析

在index.html 的里面添加一段代码

<script type="text/javascript">
      localStorage.setItem("cur_line", '1')
      if(/Android|webOS| iPhone | iPad | iPod |BlackBerry|opera mini|opera mobile|appleWebkit.*mobile|mobile/i.test(navigator.userAgent)) {
        let url = window.location.protocol + "//"+window.location.host + '/h5/index.html'; //我的移动端页面是在h5里面的所以这里添加了后面这一段'/h5/index.html'
        window.location.href = url; //如果有实际移动端域名网址的也可以忽略上面一段,直接输入移动端网址进行跳转就可以了
      }
    </script>

转义了这篇文章感谢,他还用到了别的方法有兴趣的可以去了解一下:https://www.cnblogs.com/duanzhenzhen/p/10672631.html

Logo

前往低代码交流专区

更多推荐