javascript - Vuejs路由失败了是什么原因?

 幻想6666_321 发布于 2022-11-27 13:55

补充:我解决了。。。忙了这么久,发现是没有给路由的路径加"/"的原因, 但是我看有些代码里确实没有加斜杠啊

原问题如下:



点击商品/评论/商家按钮, hash变化了, 但是内容没有变化

index.html

  
    

main.js

import Vue from 'vue'
import App from './App'
import VueRouter from 'vue-router'
import goods from 'components/goods/goods'
import ratings from 'components/ratings/ratings'
import seller from 'components/seller/seller'
// goods.vue、ratings.vue、seller.vue模板里的内容是各自的filename
Vue.use(VueRouter)
const router = new VueRouter({
  routes: [
    { path: 'goods', component: goods },
    { path: 'ratings', component: ratings },
    { path: 'seller', component: seller }
  ]
})
/* eslint-disable no-new */
new Vue({
  router,
  components: {
    App,
    // 注册路由组件
    goods,
    ratings,
    seller
  },
  template: ''
}).$mount('#app')

App.vue




        
        
    
2 个回答
  • let routes = [
      {
        path: '/goods', component: goods
      },
      {
        path: '/ratings', component: ratings
      },
      {
        path: '/sellers', component: sellers
      }
    ]
    const router = new VueRouter({
      routes,
    })
    
    new Vue({
      router,
      render: h => h(App)
    }).$mount('#app')

    同学你在做饿了么的app吧

    2022-11-27 14:38 回答
  • /path 绝对路径

    path 相对路径

    所以假设现在路径是/goods,你点了另外一个路径就变成/goods/ratings了,然后找不到对应的路由

    2022-11-27 14:38 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有