这是main.jsimportVuefrom'vue'importVueRouterfrom'vue-router';importAppfrom'./App'importRoutesfrom'./router'Vue.use(VueRouter)letrouter=newVueRouter({Routes})newVue({router,render:h=>h(App)}).$mount("#app")这是App.vue商品评论商家这是router/index.jsimportVuefrom'vue'importRouterfrom'vue-router'importgoodsfrom'@/components/goods/goods'importcommentfrom'@/components/comment/comment'Vue.use(Router)exportdefaultnewRouter({routes:[{path:'/comment',name:'comment',component:comment},{path:'/goods',name:'goods',component:goods}]})这是组件Iamgoods请问为什么App.vue的内容出现,App.vue的router-link点击地址也跳转,但是router-view不能渲染出组件中的内容
2 回答
Smart猫小萌
TA贡献1911条经验 获得超7个赞
楼主,你好~main.js里的写法有问题。改成下面的试试//这是main.jsimportVuefrom'vue'importAppfrom'./App'importrouterfrom'./router'newVue({//这里引用的就是你router.js实例化好的对象router,render:h=>h(App)}).$mount("#app")
Helenr
TA贡献1780条经验 获得超3个赞
你在router/index.js已经导出newRouter;就已经不需要在main.js进行,所以直接删除这部分代码letrouter=newVueRouter({Routes})下面修改为这样newVue({Routes,render:h=>h(App)}).$mount("#app")----补充exportdefaultnewRouter({routes:[{path:'/comment',name:'comment',component:comment},{path:'/goods',name:'goods',component:goods}]})修改为exportdefaultnewRouter({[{path:'/comment',name:'comment',component:comment},{path:'/goods',name:'goods',component:goods}]})
添加回答
举报
0/150
提交
取消