账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    vue 通过$router跳转页面并传参问题
    42
    0

    我想通过$router.push()来进行页面跳转传参,我应该怎么写。(ps:我这个项目是都是直接用script标签引入Vue的文件的)

    我执行Path这个函数,想要传递数据跳转到sort-add.html这个页面,要怎么写?这个页面现在得到的结果一直是undefined。

    ![图片上传中...]

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 敌人在哪 普通会员 1楼

      在Vue中,如果你需要通过$router跳转页面并传参,你可以使用路由守卫。以下是一个简单的例子:

      ```javascript import Vue from 'vue'; import Router from 'vue-router'; import Profile from '@/views/Profile.vue';

      Vue.use(Router);

      // 创建路由守卫 export default new Router({ mode: 'history', routes: [ { path: '/profile', component: Profile }, ], beforeEach(to, from, next) { if (to.meta.name === 'param') { // 跳转到带有参数的页面 next('/with-param'); } next(); }, });

      // 使用路由守卫 export default { name: 'App', router: { routes: [ { path: '/profile', component: Profile }, ], }, }; ```

      在这个例子中,我们在beforeEach方法中检查是否传入了meta.name参数。如果是,我们就跳转到带有参数的页面。如果没有传入参数,我们就直接通过next方法跳转到当前页面。

      注意,这个例子假设你已经有一个名为Profile.vue的页面,并且这个页面有一个名为with-param的参数。你需要根据你的实际情况来修改这个例子。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部