vuex mapState使用
<template>
<div>
{{count}}
<button @click="handleIncrease">+5</button>
<button @click="handleDecrease">-5</button>
<button @click="handleRouter">跳转到 HelloWorld3</button>
<button @click="showRouter">展示路由</button>
</div>
</template> <script>
import { mapState } from 'vuex'
export default {
name: 'HelloWorld2',
computed: {
// count(){
// return this.$store.state.count;
// },
//与上面效果一样
...mapState({
count: state => state.count
})
},
methods: {
handleIncrease() {
this.$store.commit('increase', 5);
},
handleDecrease() {
this.$store.commit('decrease', 5);
},
handleAsyncIncrease() {
this.$store.dispatch('asyncIncrease');
},
handleRouter() {
this.$router.push('/HelloWorld3');
},
showRouter() {
console.log(this.$router);
console.log(this.$router.push);
}
}
};
</script> <!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped> </style>
<template><div>{{count}}<button @click="handleIncrease">+5</button><button @click="handleDecrease">-5</button><button @click="handleRouter">跳转到 HelloWorld3</button><button @click="showRouter">展示路由</button></div></template>
<script>import { mapState } from 'vuex'export default {name: 'HelloWorld2',computed: {//count(){//return this.$store.state.count;//},//与上面效果一样...mapState({count: state => state.count})},methods: {handleIncrease() {this.$store.commit('increase', 5);},handleDecrease() {this.$store.commit('decrease', 5);},handleAsyncIncrease() {this.$store.dispatch('asyncIncrease');},handleRouter() {this.$router.push('/HelloWorld3');},showRouter() {console.log(this.$router);console.log(this.$router.push);}}};</script>
<!-- Add "scoped" attribute to limit CSS to this component only --><style scoped>
</style>
vuex mapState使用的更多相关文章
- vuex mapState、mapGetters、mapActions、mapMutations的使用
例子: index.js import Vue from 'vue' import Vuex from 'vuex' import mutations from './mutations' impor ...
- Vuex mapState的基本使用
mapState把Store中的state映射到组件中的计算属性 Store文件 import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) ...
- Vue 状态管理之vuex && {mapState,mapGetters}
1 # 一.理解vuex 2 1.概念:专门在Vue中实现集中式状态(数据)管理的一个Vue插件,对vue应用中多个组件的共享状态进行集中式的管理(读写),也是一种组件间通信的方式,且适用于任意组件间 ...
- vuex 中关于 mapState 的作用
辅助函数 Vuex 除了提供我们 Store 对象外,还对外提供了一系列的辅助函数,方便我们在代码中使用 Vuex,提供了操作 store 的各种属性的一系列语法糖,下面我们来一起看一下: mapSt ...
- [转] Vuex入门(2)—— state,mapState,...mapState对象展开符详解
1.state state是什么? 定义:state(vuex) ≍ data (vue) vuex的state和vue的data有很多相似之处,都是用于存储一些数据,或者说状态值.这些值都将被挂载 ...
- vuex中mapState、mapMutations、mapAction的理解
当一个组件需要获取多个状态时候,将这些状态都声明为计算属性会有些重复和冗余.为了解决这个问题,我们可以使用 mapState 辅助函数帮助我们生成计算属性. // 在单独构建的版本中辅助函数为 Vue ...
- 初识vuex
1.简介 vuex是 vue官方推荐的一个状态管理器.当我们遇到很多状态改变时,组件之间的通信就会变得复杂,这时候vuex的强大就展现出来. 我们从vuex的原理以及vuex的api两个部分介绍vue ...
- vuex 使用文档
安装 直接下载CDN 引用 <script src="/path/to/vue.js"></script> <script src="/pa ...
- Vue状态管理vuex
前面的话 由于多个状态分散的跨越在许多组件和交互间各个角落,大型应用复杂度也经常逐渐增长.为了解决这个问题,Vue提供了vuex.本文将详细介绍Vue状态管理vuex 引入 当访问数据对象时,一个 V ...
随机推荐
- 【转】一个java页游服务器框架
源地址:http://www.cnblogs.com/metoy/p/4305326.html?utm_source=tuicool&utm_medium=referral 一.前言 此游戏服 ...
- How to modify a compiled Android application (.apk file)
Today I’d like to share with you my findings about how an existing .apk file can be modified. An .ap ...
- linux系统初始化——sysinit文件写法详解
sysinit文件写法详解 sysinit文件是linux初始化文件系统时执行的第一个脚本文件.它主要做在各个运行级别中进行初始化工作,包括: 启动交换分区;检查磁盘;设置主机名;检查并挂载文件系统; ...
- Bzoj3227 [Sdoi2008]红黑树(tree)
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 204 Solved: 125 Description 红黑树是一类特殊的二叉搜索树,其中每个结点被染 ...
- 【UVA10561】Treblecross(SG函数)
题意:有n个格子排成一行,其中一些格子里面有字符X.两个游戏者轮流操作,每次可以选一个空格,在里面放上字符X. 如果此时有3个连续的X出现,则该游戏者赢得比赛.初始条件下不会有3个X连续出现. 判断先 ...
- 1月24日考试(ftp密码)
错因分析 ♦对文件的保存不够恰当,例如第一题和第三题的题目,我是真的很愤怒,第一题在我写了一个多小时,终于样例成功.可是当我再一次打开文件时,里面只有我最开始的代码,谁可以告诉我这是为什么(我绝对保存 ...
- python3字符串操作总结
字符串截取 >>>s = 'hello' >>>s[0:3] 'he' >>>s[:] #截取全部字符 'hello' 消除空格及特殊符号 s. ...
- layui如何使用内部jQuery?
遇到问题情境: 由于Layui部分内置模块依赖jQuery,所以没有单独引入jQuery,但是在使用$常规写法获取dom元素时,提示未定义 出现问题的原因: 由于Layui部分内置模块依赖jQuery ...
- ByteBuffer的介绍
转摘 有一个问题需要明确:为什么要使用bytebuffer,它比byte比起来有什么优点? 很简单:为了提高IO的效率.怎样提高的,这个还得google一下. 记住几个标志的含义:position[0 ...
- (入门SpringBoot)SpringBoot发送邮件(十一)
SpringBoot配置邮件服务: 1.引入jar <!-- 邮件 --> <dependency> <groupId>org.springframework ...