0

在歌曲组件中,我有一个其他专辑的列表,所以每当我点击一个时,它应该将我重定向到 /songs/:id。每张专辑都有自己的 id。

这适用于 Home 或任何其他组件,但每当我尝试从 /songs/1 到 /songs/2 时,它都不起作用。URL 发生变化,但网页保持不变。

这是我的路由器 index.js 文件。

import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
  },
  {
    path: '/songs/:id',
    name: 'Songs',
    component: () => import('../views/Songs.vue')
  },
  {
    path: '/videos/:title/:index',
    name: 'Videos',
    component: () => import('../views/Videos.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  routes
})

export default router

我在谷歌上搜索了一下,但似乎没有什么对我有用。

4

1 回答 1

0
  1. 导入您song.vueindex.js
import Songs from '../views/Songs.vue'
  1. 检查你的../views/Songs.vue

你的localhost.url/mainapp/songs/1

其中 '1' 是一个名为 'id' 的参数(如 /song/:id 的 URL),请尝试:

this.$route.params.id

于 2021-01-27T20:44:47.637 回答