700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > VUE判断是移动端还是PC端进入对应的主页

VUE判断是移动端还是PC端进入对应的主页

时间:2018-08-26 01:39:55

相关推荐

VUE判断是移动端还是PC端进入对应的主页

app.vue判断的方法,根据 "path" 这个标识,如果本地存的标识!==pathIdentification的时候,证明不是在home页里:

export default {data () {return {}},methods: {_isMobile () {const 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}},mounted () {console.log('路由', localStorage.getItem('path'))const path = localStorage.getItem('path')if (path !== 'pathIdentification') {console.log('进入了')if (this._isMobile()) {console.log('手机端')this.$router.replace('/phoneLogin')} else {console.log('pc端')this.$router.replace('/login')}}}}

跳转到pc首页/移动端首页的时候,本地添加一个标识,当关闭这个页面的时候,再销毁,这样就能解决刷新就跳转到首页的问题

export default {mounted () {console.log('移动端home路由', this.$route.path)const id = 'pathIdentification'localStorage.setItem('path', id)},destroyed () {localStorage.removeItem('path')}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。