vue-router路由传参有两种方法:
1、params传参
2、query传参
用params传参,F5强制刷新参数会被清空,用query传参,由于参数适用路径传参的所以F5强制刷新也不会被清空。(传参强烈建议适用string)
import ArticleIndex from '@/pages/twitter/article/Index'; import ArticleDetailIndex from '@/pages/twitter/article/articleDetail/IndexDetail'; export default new Router({ routes: [ { path: '/article', name: ArticleIndex.name, component: ArticleIndex, meta: { title: '文章管理', }, }, { path: '/article/articledetail', name: ArticleDetailIndex.name, component: ArticleDetailIndex, meta: { title: '文章管理', }, }, ] })传参: params
this.$router.push({ name: `ArticleIndex`, params: { page: '1', code: '8989' } })取值: this.route.params
this.code = this.$route.params.code传参:query
this.$router.push({ name: `ArticleIndex`, query: { page: '1', code: '8989' } })取值: this.$route.query
this.code = this.$route.query.code
