在歌曲组件中,我有一个其他专辑的列表,所以每当我点击一张专辑时,它应该将我重定向到 /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
我在谷歌上搜索了一下,但似乎对我没有任何作用。
答案 0 :(得分:0)
song.vue
中导入您的index.js
import Songs from '../views/Songs.vue'
../views/Songs.vue
你的localhost.url/mainapp/songs/1
其中 '1' 是一个名为 'id' 的参数(网址如 /song/:id),尝试使用:
this.$route.params.id