Vue项目安装(前端)+Vuex指南

1 篇文章 0 订阅

typora-copy-images-to: upload

vue create myvue

Vue项目安装


1.主要功能选择

image-20210408234514490

2.版本image-20210214005551832
3.路由模式:history("/")写no hash("#")是yes image-20210408234501260
4.预处理器–选择less语法(css)image-20210214005657709
5.语法检测eslint–默认

image-20210408234431341

6.保存时进行语法检测

image-20210408234420046

7.In dedicated config files
您喜欢将Babe 1、ESLint等的配置放在哪里?—放在专用配置文件中/放在pack.json文件中

image-20210214010120939

8.是否作为以后的模板–NO

Vux如何使用

1.在./store.js中操作image-20210408234400955

2.在./main.js中操作

image-20210314173926675

3.创立子组件

components内建立子组件

image-20210314184154224

4.在父组件导入子组件-注册-使用

image-20210314184904230

5.在store.js创立全局共享数据

image-20210314185212331

6.共享数据使用方式–子组件

1.第一种 子组件中通过this.$store.state.全局数据名称

image-20210314185304671

在template中使用this.$store中this可以省略

image-20210314185336765

2.第二种 子组件中通过 mapState

image-20210314185617427

image-20210314190034196

7.Mutation操作全局共享数据

1.在index.js的new Vuex中定义全局操作的方法

image-20210314190636659

image-20210314191150381

2.在子组件中使用方法

image-20210314190844551

image-20210314191214604

注意image-20210314191440564

这种方法不推荐,为错误操作方法,不方便维护

8.Mutation操作全局数据时传递参数, 自定义变化值

1.在index.js的new Vuex中定义全局操作的方法,并加入需要传递的变量

image-20210314191641497

2.触发时传递参数
第一种方式

image-20210314191931893

第二种方式 通过 mapMutations

注意: 在index.js中定义一致

image-20210314192631423

注意 …mapMuations写在methods里面

image-20210314193635951

注意: mutation里面不支持异步操作 – 如计时器

image-20210314202537519

9.Action(处理异步任务–按下按钮后延时改变数据)

-----不能直接操作state数据,需要借助context.commit操作mutation里面的方法

1.1在index.js的new Vuex中定义需要异步操作的方法,commit(括号里面填的mutation里面的方法)

image-20210314203524081

1.2必须在actions中commit的是mutations里面的方法

image-20210314205623017

2.在子组件中定义触发的方法–this.$store.dispatch(‘addAsync’)

image-20210314204209624

image-20210314210734421

10.Action(处理异步任务–按下按钮后延时改变数据,改变为自定义参数)

-----不能直接操作state数据,需要借助context.commit操作mutation里面的方法,同时传入参数

1 在./index.js的new Vuex中定义需要异步操作的方法,commit(括号里面填的mutation里面的方法)

image-20210314213331373

2.1第一种触发 通过 this.$store.dispatch(‘subAsync’,5)

image-20210314214459170

2.2 第二种触发 通过 import{mapActions}

image-20210314215148839

注意 …mapActions 也是写在methods里面

image-20210314220340644

11.行内形式改写

image-20210314221316283

image-20210314221729365

12.Getter 数据加工,调用store里面state的数据重新包装后生成–不会修改原数据


image-20210314221945608

定义方法 在./index.js 中

  getters:{
    showNum(state){
      return '当前最新的数量是['+state.count+ ']'
    }
  },

使用方法 在子组件中----第一种 this.$store.getters/showNum 这里没有括号,需要注意

image-20210314222457931

使用方法 在子组件中—第二种

image-20210314222720356

image-20210408234239231

注意 第三步 showNum没有括号

在Vue使用组件库----ant-design-vue

1. 安装npm i --save ant-design-vue
2. 在./main.js中导入包

image-20210408234207393

使用 提示消息

image-20210408234222467

owNum没有括号

在Vue使用组件库----ant-design-vue

1. 安装npm i --save ant-design-vue
2. 在./main.js中导入包

image-20210408234207393

使用 提示消息

image-20210408234222467

例子

import { queryBigListIdWithFirstStyleWithList } from '@/api/survey/systemCall/cloudComputing'

const cloudComputing = {
  state: {
    bigList: {},
    firstEditStyle: false
  },
  mutations: {
    SET_BigList(state, data) {
      state.bigList = data
    },
    SET_EditStyle(state, data) {
      state.firstEditStyle = data
    }
  },
  actions: {
    /* 获取列表数据 */
    InitListData({ commit }, param) {
      return new Promise((resolve, reject) => {
        queryBigListIdWithFirstStyleWithList(param)
          .then((res) => {
            commit('SET_BigList', res.data)
            commit('SET_EditStyle', res.data.firstEdit)
            resolve(res)
          })
          .catch((error) => {
            reject(error)
          })
      })
    }
  }
}

export default cloudComputing

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值