返回

Vue3 - 渲染查询参数

发布时间:2022-08-01 05:41:08 277

总的来说,我对 Vue 还是很陌生,尤其是 Vue3。我有一条/mypage采用一个查询参数的路由,id例如/mypage?id=hjhj.

我想要实现的是在/mypage?id=hjhj

router/index.js

const isServer = typeof window === 'undefined';

const history = isServer ? createMemoryHistory() : createWebHistory();

const routes = [{

        path: '/',

        name: 'Home',

        component: Home,

    },

    {

        path: '/about',

        name: 'About',

        component: About,

    },

    {

        path: '/mypage',

        name: 'mypage',

        component: MyPage,

        props: (route) => ({

            foo: route.query.foo

        }),

    }

];

const router = createRouter({

    history,

    routes,

});

export default router;

MyPage.vue

<template>

   <h2>Home</h2>

   <h3>{{ this.foo }}</h3>

</template>

<script>

   export default {

     props: {

       foo: {

         type: String,

         default: null,

       },

     },

   };

</script>

结果:

我应该在“主页”下方看到 hjhj

特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(1)
按点赞数排序
用户头像
相关帖子
下一篇
如何使用卡尔曼滤波器的校正测量 2022-08-01 03:38:24