javascript - 在 Vuex 中可以跳过操作并直接从组件提交突变吗?
问题描述
每次出现这个问题时,答案总是相同的——动作是为了异步。而且我知道在未来版本的 Vuex 动作和突变将被合并。
但是,嘿,我可以直接从我的组件方法中进行异步调用。例如,为什么这被认为是一种不好的做法?异步在这里不是问题。那么为什么我什至需要行动呢?
methods:
{
async fetchTodos()
{
this.$store.commit('isLoading', true)
const result = await Todos.fetchAll()
this.$store.commit('setTodos', result.data)
this.$store.commit('isLoading', false)
}
},
解决方案
推荐阅读
- angular - 在 post 方法中通过 angular 向 .net 发送参数
- php - 我正在使用 cakephp 4.0。我尝试在 cloudinary (Laminas\Diactoros\UploadedFile) 中上传图像
- swift - Crashlytics - 无法添加自定义键,它们不会在崩溃时被捕获
- php - 如何使用 PHP 数组函数在数组中查找值并取消设置?
- python-3.x - pandas:根据另一列中的条件更改一列的前一个单元格值
- optimization - 如果存在多个这种类型的查询,我们如何找到给定数字 x 在 l,r 范围内的数组元素的异或?
- javascript - webpack 对 *.js 的意外修改
- python - 如何将我的知识图存储在数据库中以回答搜索查询?
- python-3.x - 在字典Python中查找最大值
- html - 使用动态类对象创建材质表