You commit changes to state in Vuex using defined mutations. You can easily access these state mutations in your template using mapMutations. This lesson shows you have to wire together your Vue.js template with your Vuex store using mutations and mapMutations.

store/index.js:

import Vuex from 'vuex'

const store = () => new Vuex.Store({
state: {
counter: 0
}, mutations: {
increment: (state) => {
state.counter++
},
decrement: (state) => {
state.counter--
}
}
}) export default store

pages/index.vue:

<template>
<div>
Counter: {{counter}}
<button @click='increment'>+</button>
<button @click='decrement'>-</button>
</div>
</template> <script>
import { mapState, mapMutations } from 'vuex' export default {
computed: {
...mapState({
counter: (state) => state.counter
})
}, methods: {
...mapMutations([
'increment',
'decrement'
])
}
}
</script>

最新文章

  1. Windows 下 zip 版的 MySQL 的安装
  2. 2015年12月10日 spring初级知识讲解(二)最小化Spring XML配置 注解
  3. 一段检测IP设备是否在线的代码
  4. csuoj 1395: Timebomb
  5. Linux Mysql 1130错误解决
  6. wechat
  7. 炼数成金hadoop视频干货03
  8. java jvm学习笔记六(实现写自己的安全管理器)
  9. hdu 4710 Balls Rearrangement
  10. 可解压带中文名称文件的zip包
  11. c#indexof使用方法
  12. hdu 1059 Dividing 多重背包
  13. RQPro 公募FOF策略实例——晨星基金筛选和风险平价配置
  14. ajax调用数据案例,二级联动
  15. 排序1,2......n的无序数组,时间复杂度为o(n),空间复杂度为o(1)
  16. Cocos Creator Animation 组件
  17. Dreamweaver编辑区下方的属性栏显示
  18. python解决json序列化时间格式
  19. Hive学习01-基础常见问题
  20. 7.3 Models -- Creating And Deleting Records

热门文章

  1. Autodesk 招聘Revit二次开发咨询顾问,与Autodesk全球团队紧密合作,提高职业生涯的好机会
  2. 使用TCP协议的NAT穿透技术 (转载)
  3. Aruba 云服务代金券
  4. php中类的持久化如何实现
  5. Linux下基于LDAP统一用户认证的研究
  6. 用djbdns为域名解析服务护航
  7. 洛谷 P2026 求一次函数解析式
  8. 27. Spring Boot 部署与服务配置
  9. 利用formdata对象上传文件时,需要添加的参数
  10. nuxt按需引入 element-UI、自定义主题色(终极按需引入)