简体   繁体   English

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

[英]How do I install vue router plugin with Vue CLI 3?

So I've been setting up projects with the Vue CLI 3.0.0rc8 and it is a pretty awesome tool but I have a problem. 因此,我一直在使用Vue CLI 3.0.0rc8设置项目,这是一个非常出色的工具,但是我遇到了问题。 I am trying to install the router plugin for my project however when I use vue add router , I get this: 我正在尝试为我的项目安装路由器插件,但是当我使用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.

Could someone please explain why this isn't working? 有人可以解释为什么这不起作用吗?

PS I've also tried vue add @vue/router and I get the same message. PS我也尝试过vue add @vue/router ,我得到相同的消息。

I've got it! 我懂了! Thank you to @dnhyde for your suggestion. 谢谢@dnhyde的建议。 But if you actually want to install it as a plugin you need to update the Vue CLI to 3.0.0-rc.10. 但是,如果您实际上想将其安装为插件,则需要将Vue CLI更新到3.0.0-rc.10。 Do so with this command: npm i -g @vue/cli . 使用以下命令执行此操作: npm i -g @vue/cli

Hi I had a similar issue, the best way to add Vue router in my case was to select it from the start with vue create my-project command. 嗨,我遇到了类似的问题,在我的情况下,添加Vue路由器的最佳方法是从vue create my-project命令开始选择它。 Or you can manually add the router.js file and the Vue.use(router) in your main following the template vue-cli creates for you. 或者,您可以按照为您创建的模板vue-cli手动在主目录中手动添加router.js文件和Vue.use(router)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM