Vuex----Actions
Actions用于处理异步任务。
如果通过异步操作变更数据,必须通过 Action,而不能使用Mutation,但是在 Action中还是要通过触发Mutation的方式间接变更数据。
注意: 在Actions 中不能直接修改 state中的数据,要通过 mutations修改。
方法1:this.$store.dispatch
const store = new Vuex.store({
state: {
count: 0
},
mutations: {
add(state) {
state.count++
}
},
actions: {
addAsync(context) {
setTimeout(() => {
context.commit('add')
}, 1000);
}
},
})
methods:{
handle(){
this.$store.dispatch('addAsync')
}
}
方法2:导入 mapActions 函数
import {mapActions} from 'vuex'
actions: {
subAsync(context){
setTimeout(() => {
context.commit('sub')
}, 1000);
}
}
methods:{
...mapActions(['subAsync']),
decrementAsync(){
this.subAsync()
}
}
Vuex----Actions的更多相关文章
- [Vuex] Perform Async Updates using Vuex Actions with TypeScript
Mutations perform synchronous modifications to the state, but when it comes to make an asynchronous ...
- [Nuxt] Update State with Vuex Actions in Nuxt.js
You can conditionally add classes to Vue.js templates using v-bind:class. This will help display the ...
- [Nuxt] Use Vuex Actions to Delete Data from APIs in Nuxt and Vue.js
You'll begin to notice as you build out your actions in Vuex, many of them will look quite similar. ...
- [Nuxt] Build a Vue.js Form then use Vuex Actions to Post to an API in Nuxt
The default behavior of submitting an HTML form is to reload the page. You can use the Vue.js @submi ...
- vuex(1.0版本写法)
Vuex 是一个专门为 Vue.js 应用所设计的集中式状态管理架构. 官方文档:http://vuex.vuejs.org/zh-cn/ 2.0和1.0都能在此找到 每一个 Vuex 应用的核心就 ...
- vuex构建笔记本应用学习
vuex:针对vue应用派生的专门管理应用state的工具,state可以理解为我们组件需要操作的data数据,都知道,vue构建spa应用的时候,随着组件规模的提升,各个子组件之间的通信如果采用子组 ...
- Vue、Vuex+Cookie 实现自动登陆 。
概述 1.自动登陆实现思路. 2.vuex + cookie 多标签页状态保持. 自动登陆的需求: 1.登陆时勾选自动登陆,退出登陆或登陆到期后再次登陆后自动填写表单(记住密码)或访问登陆页自动登陆. ...
- 个人对vuex的表象理解(笔记)
一个东西,首先要知道为什么用它,为什么要vuex,官方解释为了解决繁杂事件订阅和广播,那么事件的$dispatch,$on,怎么就复杂了?许多人是不是感觉后者还挺简单的,对的 如果简单小型项目,那么不 ...
- [转] 对vuex的表象理解(笔记)
一个东西,首先要知道为什么用它,为什么要vuex,官方解释为了解决繁杂事件订阅和广播,那么事件的$dispatch,$on,怎么就复杂了?许多人是不是感觉后者还挺简单的,对的 如果简单小型项目,那么不 ...
- 【翻译】使用Vuex解决Vue中的身份验证
翻译原文链接:https://scotch.io/tutorials/handling-authentication-in-vue-using-vuex 我的翻译小站:https://www.zcfy ...
随机推荐
- The first python article
Smile is the most beautiful language! and Python so on !
- vue pdf下载(非预览)
只需改掉 选择器名称 和 图片存放的URL 即可使用 downloadimg(){ let _this=this let url = 'https://PDF或者图片路径/Merged.pdf' le ...
- Linux下查找并杀死 zombile 和 stopped 进程
用top命令查看系统运行情况,突然发现stopped和zombile进程个数居然不是0. [root@myos software]# top top - 11:20:17 up 60 days, 17 ...
- MVC页面加载速度优化小记
前言: 最近做一个地图展示页面,业务初期没什么问题,运行一阵后报错: Error during serialization or deserialization using the JSON Jav ...
- Flink Concept Timely Stream Processing -Flink概念及时流处理
目录 介绍 时间概念:事件时间和处理时间 事件时间和水印 并行流中的水印 延迟 窗口 翻译来源- Concept Timely Stream Processing 介绍 及时的流处理是有状态流处理的扩 ...
- string 字符串模块操作
1. 常用方法 2.字符串常量 3.字符串模板Template 通过string.Template可以为Python定制字符串的替换标准,下面是具体列子: >>>from strin ...
- 单个表空间文件个数达到上限 ORA-01686
# 问题概述因在oracle数据库表空间管理中的时候 报 ORA-01686: max # files (1023) reached for the tablespace GPRS SQL> a ...
- leetcode 310. 最小高度树 【时间击败70.67%】 【内存击败89.04%】
数组替代队列,从超时到击败70%,用tree[0]替代new一个新的ArrayList,上升10% 思想是遍历一遍,删除度为1的节点,答案只可能为1或2 1 public List<Intege ...
- Java方法之递归详解【重点】
递归详解 A方法调用B方法,我们很容易理解! 递归就是:A方法调用A方法!就是自己调用自己. 利用递归可以用简单的程序来解决一些复杂的问题.它通常把一个大型复杂的问题层层转化为一个与原问题相似的规模较 ...
- RMAN架构
关于 RMAN 环境 Recovery Manager 环境由在备份和恢复策略中发挥作用的各种应用程序和数据库组成. RMAN 环境的组件 组件 描述 RMAN 客户端 管理目标数据库的备份和恢复操作 ...