今天又是一个奇怪的小知识,这个贼长的函数可以实现把字符串作为URL进行编码
你们浏览网页会不会遇到token过期导致自动退出登录页面,在你从新登录的时候肯定会想回到之前的页面,这就是它的应用场景
// 去到登录页
// this.$router.push('/login?return_url=当前的路径')
// 跳转路由-回登陆
// 如何获取当前页面的地址 : this.$route.fullPath
// this.$route.path只有路径的信息
// this.$route.fullPath:路径+查询参数的信息
console.log(1)
this.$router.push(
'/login?return_url=' + encodeURIComponent(this.$route.fullPath)
)
它还有个配套的API,decodeURIComponent()可以对编码解码