官方文件:https://cli.vuejs.org/#getting-started
Install:
先用npm安装
npm install -g @vue/cli# ORyarn global add @vue/cliCreate a project:
接下来就是创造阶段,分为两种方法
vue create my-project# ORvue ui
输入指令 vue create my-project
(后面的my-project为资料夹名称,可以自己设定)
选择相关选项,(Router、CSS记得打勾!)
` Use history mode for router? (Requires proper server setup for index fallback in production) (Y/n)` 可以先选择(n)` Save this as a preset for future projects? (y/N)` 看你需不需要把这些设定储存起来,先选择(N)设定完成后就开始建档了!
跑完后进入刚刚创建的资料夹,在这边为my-project
下指令 npm run serve
运行完后会出现以下两个连结,点进去就是你的网页档案了!
App running at: - Local: http://localhost:8080/ - Network: http://192.168.0.142:8080/
创建后有一些档案有出错Parsing error: No Babel config file detected for C:\Users\USER\Desktop\vue cli\my-project\vue.config.js. Either disable config file checking with requireConfigFile: false, or configure Babel so that it can find the config files.
可以在 .eslintrc 档案里尝试增加
"parserOptions": { requireConfigFile : false }
错误就会消失。
另一个错误如下图
解决方法如下:
◎ 找到 jsconfig.json档案,新增 "compilerOptions":{"jsx": "preserve"}
◎ 查看是否安装了Vetur插件,在vscode里的设置搜寻eslint选取左边的Vetur,取消勾选Validate vue-html in using eslint-plugin-vue
另一种安装法是
输入指令vue ui
新增专案,后面会遇到跟cmd安装十一样的选项,接下来就完成了!