初始化VUE并创建项目手册

初始化VUE并创建项目手册

一、前端环境搭建

1.1 安装NodeJs

https://nodejs.org/zh-cn
下载LTS版本,下载安装完成后环境配置添加安装路径
---------------------------------------
npm config set registry https://registry.npm.taobao.org/
设置镜像仓库提升下载速度
---------------------------------------
npm config get registry
检查是否修改成功
---------------------------------------
npm config ls
查看默认配置
---------------------------------------
npm config set cache "D:\Node安装目录\node_cache"
npm config set prefix "D:\Node安装目录\node_global"
配置缓存和下载目录
---------------------------------------

1.2 安装Vue-Cli环境

npm install -g @vue/cli
或
yarn global add @vue/cli
---------------------------------------
npm list
查看已安装的模块
npm list -g
查看已安装的全局模块
---------------------------------------
npm uninstall 模块名
卸载模块
---------------------------------------

二、创建vue项目

2.1 找到存放的项目文件夹,在地址栏输入CMD打开命令窗口创建项目名文件夹。

vue create 项目名

2.2 选择模式,常用选择为Manually select features手动选择。

2.3 勾选自己的配置,空格选中,A全选,回车确认。

注:常用选择为Babel、Router、Vuex、CSS Pre-processors
TypeScript 支持使用 TypeScript 书写源码
Progressive Web App (PWA) Support PWA 支持。
Router 支持 vue-router 。
Vuex 支持 vuex 。
CSS Pre-processors 支持 CSS 预处理器。
Linter / Formatter 支持代码风格检查和格式化。
Unit Testing 支持单元测试。
E2E Testing 支持 E2E 测试。

2.4 选择VUE版本,常用选择为VUE2。

2.5 选择路由器模式是history或hash模式,常用选择为hash模式,所以输入n代表no。

2.6 选择css预处理器,常用选择less。

2.7 这些配置的模块是单独放一个文件夹,还是放在package.json文件夹里,常用选择是单独放一个文件夹里。

2.8 表示配置是否保存为预设,下次创建项目可以直接选择配置名创建,根据需要选择。

2.9 创建完成。CD进入创建的项目名文件夹,输入npm run serve或yarn serve启动项目,复制地址到浏览器访问即可。

三、调整项目

3.1 打开VSCODE,因为我用的是Prettier插件,所以在项目根目录创建.prettierrc文件配置格式化

{
  /* 单引号包含字符串 */
  "singleQuote": true,
  /* 不添加末尾分号 */
  "semi": false,
  /* 缩进大小为2 */
  "tabWidth": 2,
  /* 缩放风格为空格 */
  "useTabs": false,
  /* 在对象属性添加空格 */
  "bracketSpacing": true,
  /* 只有一个参数的箭头函数参数带空格 */
  "arrowParens": "always",
  /* 打印宽度 */
  "printWidth": 80,
  /* 最后一行不添加逗号 */
  "trailingComma": "none",
  /* 末尾空行 */
  "endOfLine": "auto"
}

3.2 安装element-ui

项目目录下输入
npm i element-ui -S
安装依赖包
---------------------------------------
找到main.js
//导入ElementUI
import ElementUI from 'element-ui'
//导入ElementUI样式
import 'element-ui/lib/theme-chalk/index.css'
//配置使用ElementUI
Vue.use(ElementUI)

3.3 删除整理自带内容

删除src/assets/logo.png
删除src/components/HelloWorld.vue
---------------------------------------
清空src/views/AboutView.vue内容
<template>
  <div class="about">

  </div>
</template>
<style lang="less"></style>
<script>
export default {
  name: 'about',
  components: {}
}
</script>
---------------------------------------
清空src/views/HomeView.vue内容
<template>
  <div class="home">

  </div>
</template>
<style lang="less"></style>
<script>
export default {
  name: 'HomeView',
  components: {}
}
</script>
---------------------------------------
在HomeView页面加载elementui启动项目看是否正常
<el-row>
  <el-button>默认按钮</el-button>
  <el-button type="primary">主要按钮</el-button>
  <el-button type="success">成功按钮</el-button>
  <el-button type="info">信息按钮</el-button>
  <el-button type="warning">警告按钮</el-button>
  <el-button type="danger">危险按钮</el-button>
</el-row>
---------------------------------------

四、开始项目

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

NgCalo

各位赏口饭吃吧!1分也是爱!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值