亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Vue 路由器未路由到指定位置

Vue 路由器未路由到指定位置

波斯汪 2022-09-23 10:02:45
我正在將 vue 與 vue 路由器一起使用,路由在路由到子路由時不起作用。  {    path: '/user',    name: 'User',    component: User,    children: [      {        path: 'profile',        component: Profile,      },    ],  }以編程方式路由到 /用戶/配置文件<template>    <div>            <button @click="goToUserProfile()">create new</button>    </div></template><script>export default {  methods: {    goToUserProfile() {      this.$router.push('/user/profile')    // Routing doesn't work       .catch(console.log);    },  },};</script>
查看完整描述

2 回答

?
四季花海

TA貢獻1811條經驗 獲得超5個贊

為“/用戶/配置文件”提供路由名稱“配置文件”


  {

    path: '/user',

    name: 'User',

    component: User,

    children: [

      {

        path: 'profile',

        name: "Profile",

        component: Profile,

      },

    ],

  }

導航 使用路由名稱


this.$router.push({name: "Profile"});

您的用戶組件應像這樣聲明


用戶.vue


<template>

<div>

    <p>this is user component</p>

    <!-- your Profile component will replace this route-view -->

    <route-view /> 

</div>

</template>


演示

https://codesandbox.io/s/falling-bash-6dl7m


查看完整回答
反對 回復 2022-09-23
?
肥皂起泡泡

TA貢獻1829條經驗 獲得超6個贊

請確保輸入“用戶組件”模板以顯示嵌套(子)路由。<router-view></router-view>


<template>

    <div>

        <button @click="goToUserProfile()">create new</button>

        <router-view></router-view>   <!-- placeholder for children routes -->

    </div> 

</template> 

然后,您可以通過兩者訪問和this.$router.push('/user/profile')this.$router.push({ name: 'UserProfile' })


正如 Vue 路由器文檔所述:要將組件渲染到此嵌套插座中,我們需要使用 VueRouter 中的子選項。


https://router.vuejs.org/guide/essentials/nested-routes.html


希望這有幫助。


查看完整回答
反對 回復 2022-09-23
  • 2 回答
  • 0 關注
  • 132 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號