如何使用Vue CLI 3安装vue路由器插件?

时间:2018-08-05 05:52:37

标签: javascript vuejs2 vue-router

所以我一直在使用Vue CLI 3.0.0rc8设置项目,这是一个非常棒的工具,但是我遇到了问题。我正在尝试为我的项目安装路由器插件,但是当我使用vue add router时,我得到了:

(node:2706) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'routerHistoryMode' of undefined
at module.exports (/home/joshua/programs/firstwebapp/frontend/node_modules/@vue/cli-service/generator/router/index.js:10:26)
at Generator.plugins.forEach (/home/joshua/.node_modules_global/lib/node_modules/@vue/cli/lib/Generator.js:96:7)
at Array.forEach (<anonymous>)
at new Generator (/home/joshua/.node_modules_global/lib/node_modules/@vue/cli/lib/Generator.js:94:13)
at Function.runGenerator (/home/joshua/.node_modules_global/lib/node_modules/@vue/cli/lib/invoke.js:111:21)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:2706) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:2706) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

有人可以解释为什么这不起作用吗?

PS 。我也尝试过vue add @vue/router,但收到的消息仍然相同。

2 个答案:

答案 0 :(得分:3)

我知道了!谢谢@dnhyde的建议。但是,如果您实际上想将其安装为插件,则需要将Vue CLI更新到3.0.0-rc.10。使用以下命令执行此操作:npm i -g @vue/cli

答案 1 :(得分:0)

嗨,我遇到了类似的问题,在我的情况下,添加Vue路由器的最好方法是从vue create my-project命令开始选择它。或者,您可以按照vue-cli为您创建的模板手动将router.js文件和Vue.use(router)添加到您的主文件中。