vue.js - 求问vue-router的query解析的问题

查看:122
本文介绍了vue.js - 求问vue-router的query解析的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

http://127.0.0.1:8080/index.php?id=123123/#!/filter?page=1

为什么这样的网址$route.query会解析出{id: 123123, page: 1}
而不是仅仅解析"#!"后面的{page: 1}

vue-router有api只解析"#!"后面的吗? (我知道window.location.hash能获取到"#!"后的字符串。)

解决方案

这是因为在vue-router里有一个对URL处理的特殊过程:

// determine query
// note it's possible to have queries in both the actual URL
// and the hash fragment itself.
const query = location.search && path.indexOf('?') > -1
  ? '&' + location.search.slice(1)
  : location.search
self.onChange(path.replace(/^#!?/, '') + query)

源码地址:vue-router

她的作用就是从URL里,把#!之前的?部分取出来,然后拼到了URL的后面。

这篇关于vue.js - 求问vue-router的query解析的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆