Skip to content

query 传参

字符串写法

html
<router-link active-class="active" to="/home?title=Hello&time=2022-01-23">Home</router-link>

对象写法

html
<router-link active-class="active" :to="{
    path: '/home',
    query: {
        title: 'Hello',
        time: '2022-01-23'
    }
}">Home</router-link>

query 接参

  1. 路由基本用法 中提到了路由组件新增的两个属性,一是 $route,二是 $router。

  2. 上一组件传递的参数位于路由组件的 $route 中。

  3. 接参一般是写在计算属性中的。

    javascript
    computed: {
        title(){
            return this.$route.query.title
        },
        time(){
            return this.$route.query.time
        }
    }

基于 MIT 许可发布