注意(用params傳參,F5強制刷新參數會被清空,用query,由於參數適用路徑傳參的所以F5強制刷新也不會被清空。(傳參強烈建議適用string))
也可以選用sessionstorage/localstorage/cookie存儲,
params:參數不會顯示到路徑上
1:配置路徑rutes
export default new Router({
routes: [
{
path: '/testVueRouter',
name: 'TestVueRouter',
component: TestVueRouter
},
{
path: '/testVueRouterTo',
// 一定要寫name,params必須用name來識別路徑
name: 'TestVueRouterTo',
component: TestVueRouterTo
}
]
})
2:傳遞參數:用$router
<template>
3:接受參數:用$route,少個r,注意啦
<template>
query:最好也用name來識別,保持與params一致性,好記了,路徑傳參
1:路徑配置(跟params一樣,代碼不寫了)
2:傳遞參數頁
<template>
3:接受參數
<template>
下面我們採用path: '/testVueRouterTo'
1:query(成功)
<template>
<template>
閱讀更多 紛亂的雨季 的文章