安装:vue create vue-app 采用 Manually select features 形式安装。
1 2 3 4 5 6 7 8 9 10 11 12 13
//上下移动 space空格选中 a全选 i反选 enter回车确定 Vue CLI v5.0.8 ? Please pick a preset: Manually select features ? Check the features needed for your project: (Press <space> to select, <a> to toggle all, <i> to invert selection, and <enter> to proceed) ◉ Babel ◉ TypeScript ❯◯ Progressive Web App (PWA) Support ◉ Router ◯ Vuex ◉ CSS Pre-processors ◉ Linter / Formatter ◯ Unit Testing ◯ E2E Testing
Vue CLI v5.0.8 ? Please pick a preset: Manually select features ? Check the features needed for your project: Babel, TS, Router, CSS Pre-processors, Linter ? Choose a version of Vue.js that you want to start the project with (Use arrow keys) ❯ 3.x 2.x
选择vue的版本,当然是选择vue3了。
1
? Use class-style component syntax? (y/N)
是否使用Class风格装饰器? 原本是:home = new Vue()创建vue实例,用装饰器后:class home extends Vue{}。直接enter回车即选择No
1
? Use Babel alongside TypeScript (required for modern mode, auto-detected polyfills, transpiling JSX)? (Y/n)
使用Babel与TypeScript一起用于自动检测的填充? 选择yes
1
Use history modefor router? (Requires proper server setup for index fallback in production)
? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): (Use arrow keys) ❯ Sass/SCSS (with dart-sass) Less Stylus
css处理模式。看情况选择。
1 2 3 4 5
? Pick a linter / formatter config: (Use arrow keys) ❯ ESLint with error prevention only ESLint + Airbnb config ESLint + Standard config ESLint + Prettier
代码检查与代码格式. 选择 ESLint + Prettier
1 2 3
Pick additional lint features: (Press <space> to select, <a> to toggle all, <i> to invert selection, and <enter> to proceed) ❯◉ Lint on save ◯ Lint and fix on commit
项目校验格式 Lint on save 是保存时,Lint and fix on commit是提交时.选择 Lint on save
1 2 3
? Where do you prefer placing config for Babel, ESLint, etc.? (Use arrow keys) ❯ In dedicated config files In package.json
项目的配置文件存放 In dedicated config files 独立配置文件,In package.json 存放在package.json。选择 In package.json
1
? Save this as a preset for future projects? (y/N)
3. 创建store.store的本质是一个函数包括两个参数,第一个是store的名字,第二个是store的配置项。配置项中包括 state,actions和getters. state 是 store 的核心部分是需要统一管理的状态.Actions 相当于组件中的 methods即业务操作.getter 完全等同于 Store 状态的 计算值