将路径字符串匹配到 Vue 路由器参数
Match path-string to Vue Router params
我有一个像 "/foo/123/bar/456"
这样的路径字符串,它 不是 当前路径。
Vue Router 路径设置为匹配/foo/:fooid/bar/:barid
有没有办法使用 Vue Router 从字符串中检索参数?
预计:
let params = this.$router.someFunction("/foo/123/bar/456")
// params = {fooid: 123, barid: 456}
您要找的是this.$router.resolve("/foo/123/bar/456")
注意,只有你的路由中有对应的路由才会匹配。该方法将为您提供带有“参数”的对象 属性.
const matchedRoute = this.$router.resolve("/foo/123/bar/456")
// what you are looking for is under
// matchedRoute.params = {fooid: 123, barid: 456}
我有一个像 "/foo/123/bar/456"
这样的路径字符串,它 不是 当前路径。
Vue Router 路径设置为匹配/foo/:fooid/bar/:barid
有没有办法使用 Vue Router 从字符串中检索参数?
预计:
let params = this.$router.someFunction("/foo/123/bar/456")
// params = {fooid: 123, barid: 456}
您要找的是this.$router.resolve("/foo/123/bar/456")
注意,只有你的路由中有对应的路由才会匹配。该方法将为您提供带有“参数”的对象 属性.
const matchedRoute = this.$router.resolve("/foo/123/bar/456")
// what you are looking for is under
// matchedRoute.params = {fooid: 123, barid: 456}