在电脑中的合适位置新建存放项目文件的文件夹。
执行命令,进入 vue-cli 创建项目:
vue create app
选择 vue-cli 创建 vue2 项目的默认配置创建项目:



修改 package.json 文件中的 scripts 配置项:
serve 对应的配置后面加上
--open
"scripts": {
"serve": "vue-cli-service serve --open",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
项目运行起来,自动打开浏览器,访问的为 http://0.0.0.0:8081 的解决办法:vue-cli3 运行vue项目,设置vue-cli-service serve --open自动打开浏览器,跳转到http://0.0.0.0:8081 解决办法
在 vue.config.js 文件(没有该文件在项目根目录下新建一个)中的配置中添加 devServer 配置项:const { defineConfig } = require('@vue/cli-service') module.exports = defineConfig({ transpileDependencies: true, devServer: { // 开发阶段项目运行的服务器主机地址 host: 'localhost', // 端口号 port: 8081, https: false, hot: false, proxy: null } })
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13

在 vue.config.js 文件(没有该文件在项目根目录下新建一个)中的配置中添加 lintOnSave 配置项:
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
transpileDependencies: true,
devServer: {
// 主机地址
host: 'localhost',
// 端口号
port: 8081,
https: false,
hot: false,
proxy: null
},
// 关闭 eslint
lintOnSave: false
})
脚手架 5 版本默认进行了配置。
在 jsconfig.json 文件中配置 src 文件夹的别名 @,@ 代表的是 src 文件夹,配置后写文件路径可以直接写 @,方便路径的书写,不用频繁使用 ../ ./。
在 jsconfig.json 文件(没有该文件在项目根目录下新建一个)中进行配置:
脚手架生成的默认配置
{
"compilerOptions": {
"target": "es5",
"module": "esnext",
"baseUrl": "./",
"moduleResolution": "node",
"paths": {
"@/*": [
"src/*"
]
},
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
}
}