vue篇3 路由配置

本文档介绍了Vue项目的路由配置流程,包括从main.js到router.js再到具体页面的组件加载。在配置过程中遇到了两个常见错误:一是Vue.use报错,解决办法是降级vue-router版本;二是使用了运行时编译版本的Vue导致模板编译警告,解决方法是修改main.js中的渲染方式。通过这些步骤,可以成功解决Vue项目中与路由相关的常见问题。
摘要由CSDN通过智能技术生成

路由配置

思路与实例化:

main.js→router.js→具体的页面→具体的页面加载组件。如上,下,左,右的组件

一、大体框架

vue create vueinshop 

 二、

报错问题一:

Uncaught TypeError: Cannot read properties of undefined (reading 'install')
    at Vue.use (vue.runtime.esm.js?2b0e:5784:1)
    at eval (router.js?41cb:7:1)
    at ./src/router.js (app.js:1188:1)
    at __webpack_require__ (app.js:849:30)
    at fn (app.js:151:20)
    at eval (main.js?56d7:1:1)
    at ./src/main.js (app.js:1140:1)
    at __webpack_require__ (app.js:849:30)
    at fn (app.js:151:20)
    at 1 (app.js:1201:18)

解决方案:

 cnpm install vue-router@3.1.3 --save-dev

参考文章:解决- “export ‘default‘ (imported as ‘VueRouter‘) was not found in ‘vue-router‘_Vincent^_^的博客-CSDN博客 

报错问题二:

[Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build.

(found in <Root>)

main.js里面内容修改为

new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})

修改为

new Vue({
  el: '#app',
  // store,
  router,
  render: h =>h(App)
}).$mount("#app")

参考文章:vue报[Vue warn]: You are using the runtime-only..........错误_昆仑洞洞主的博客-CSDN博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值