国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

有沒(méi)有辦法在vue中設(shè)定route prop?
P粉919464207
P粉919464207 2024-04-06 11:35:59
0
1
947

我想導(dǎo)航到頁(yè)面中的特定選項(xiàng)卡

this.$router.push({
        name: "AdminNotifications",
        params: { tab: "requests" },
      })

因此在頁(yè)面內(nèi)我可以取得參數(shù)並設(shè)定選項(xiàng)卡:

mounted() {
    const routeTab = this.$route.params.tab;
    if (routeTab) this.tab = routeTab;
  }

如果目前頁(yè)面不是 AdminNotifications,則有效。

但除此之外,還有一個(gè)錯(cuò)誤: NavigationDuplicated:避免了到目前的冗餘導(dǎo)航

那麼...有沒(méi)有辦法只設(shè)定 tab 屬性,而不需要導(dǎo)航?

謝謝

P粉919464207
P粉919464207

全部回覆(1)
P粉432930081

如果您已經(jīng)到達(dá)某個(gè)路線,則無(wú)法導(dǎo)航至該路線。但是,既然您已經(jīng)在那裡,您只需將 this.tab 設(shè)定為所需的值即可:

if (this.$route.name === 'AdminNotifications') {
  this.tab = 'requests';
} else {
  this.$router.push({
    name: "AdminNotifications",
    params: { tab: "requests" },
  })
}

如果負(fù)責(zé)導(dǎo)航的元件與包含 tab 的元件不同,您可以將 tab# 參數(shù)推送到 $route

if (this.$route.name === 'AdminNotifications') {
  this.$router.replace({
    params: { tab: "requests" }
  });
} else {
  this.$router.push({
    name: "AdminNotifications",
    params: { tab: "requests" },
  })
}

在頁(yè)面元件中,將mounted 中的「watcher」替換為適當(dāng)?shù)谋O(jiān)視程序,該監(jiān)視程序?qū)?code>tab 動(dòng)態(tài)設(shè)為$route.params. tab 的任何真值:

watch: {
  '$route.params.tab': {
    handler(val) {
      if (val) {
        this.tab = val;
      }
    },
    immediate: true
  }
}
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板