【问题标题】:Vue router changing the url but not the contentVue路由器更改url但不更改内容
【发布时间】:2021-05-01 17:51:10
【问题描述】:

在歌曲组件中,我有一个其他专辑的列表,所以每当我点击一张专辑时,它都会将我重定向到 /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

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

【问题讨论】:

    标签: javascript vue.js vue-component vue-router vue-router4


    【解决方案1】:
    1. 将您的song.vue 导入index.js
    import Songs from '../views/Songs.vue'
    
    1. 检查您的../views/Songs.vue

    yourlocalhost.url/mainapp/songs/1

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

    this.$route.params.id

    【讨论】:

      猜你喜欢
      • 2019-03-28
      • 2021-01-13
      • 1970-01-01
      • 2020-04-07
      • 2018-04-18
      • 2023-01-12
      • 2018-07-25
      • 2018-08-02
      相关资源
      最近更新 更多