我在用vue init..的时候,选择安装了vue-router。于是有了两个问题

来源:5-2 vue-cli安装(下)

慕娘6352887

2017-06-06

问题1:我发现,hello页面的呈现,默认使用的路由方式。路径是src/router/index.js. 这是vue新版本的方式?

问题2:刚开始我为了证明hello页面的呈现是不是引用了src/router/index.js。于是我把index.js改成了index2.js。结果页面报错了。于是我知道确实默认引用了index.js页面。然后我把index2.js改回index.js。神奇的事情发生了。居然依然报错。我执行npm run dev也报错。这是为何?

写回答

2回答

慕娘6352887

提问者

2017-06-07

页面报错一直是:vue Cannot GET /

而命令行报错:Error: listen EADDRINUSE :::8080........此处省略......npm ERR! Failed at the vue_demo@1.0.0 dev script 'node build/dev-server.js'.

npm ERR! Make sure you have the latest version of node.js and npm installed.

npm ERR! If you do, this is most likely a problem with the vue_sell package,

......此处省略.....


0
0

fishenal

2017-06-06

  1. src/router/index.js 是router的配置, 不是hello页面, 默认路由方式肯定要引用这份配置

  2. 我看了一下 https://github.com/vuejs-templates/webpack/blob/master/template/src/main.js 模板代码,加了路由以后,肯定要在main.js里引用router from './router' 省略了index.js,改成index2.js 肯定无效。 你说的改回,报错应该是其它问题,端口占用之类的?不行你看一下报错的位置,看router这个变量能不能打出来。 

0
0

最容易上手的Vue2.0入门实战教程

快速入门Vue2.0,组件化开发一个数字产品电商平台

3966 学习 · 999 问题

查看课程