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 ...
随机推荐
- win8中写好的程序,在win7中没办法运行
没有安装相应版本的,net framework win8自带4.0 win7自带2.0 所以4.0及其以上的程序在win7跑必须安装4.0及其以上版本的framework
- 一道背包神题-Petrozavodsk Winter-2018. Carnegie Mellon U Contest Problem I
题目描述 有\(n\)个物品,每个物品有一个体积\(v_i\),背包容量\(s\).要求选一些物品恰好装满背包且物品个数最少,并在这样的方案中: (1)求出中位数最小的方案的中位数(\(k\)个元素的 ...
- hihoCoder offer 收割练习赛 74B 取球游戏
Observations 存在取球策略使得每个四连通块可以只剩一个球:保证取走一个球后仍然是个四连通块. 定义新的[相邻]关系:两球在同一行中且所在行中二者之间无其他球,或者两球在同一列且所在列中二者 ...
- [luoguP3332] [ZJOI2013]K大数查询(树套树)
传送门 一开始想的是区间线段树套权值线段树,结果好像不能实现. 然后题解是权值线段树套区间线段树. 区间线段树上标记永久化就省去了pushdown的操作减少常数. 标记永久化的话..yy不出来就看代码 ...
- linux系统初始化——inittab文件解析
inittab文件解析 inittab配置文件每行的基本格式如下. id:runlevels:action:process 其中某些部分可以为空,下面我们逐一介绍. 1.id 1-2个字符,配置行的唯 ...
- char与byte的区别
很多初学者(包括我,已经学了一年多java了)肯会对char和byte这两种数据类型有所疑惑,相互混淆,今天特地查了好多资料,对byte和char两种数据类型进行了总结和比较,先将结果与大家分享: b ...
- IDEA 注册问题,创建 和 删除项目
目录 .....2016.3/2017.1 IDEA 注册码 .....IDEA 创建项目 .....IDEA 删除项目 IDEA 注册码 复制使用别人的注册码,启动选择如下: 复制粘贴如下代码: 这 ...
- linux下常用的日志分析命令【转】
形如下面这样的access.log日志内容: 211.123.23.133 – - [10/Dec/2010:09:31:17 +0800] “GET /query/trendxml/district ...
- Render 使用
Page页面文件,重新Render 方法,目的是把页面的ViewState信息放在最后,利于页面展示速度和SEO优化. Render方法对于重新Html控件还是很好用的. private static ...
- .Net Framework 4.0: Using System.Lazy<T>
原文发布时间为:2011-04-26 -- 来源于本人的百度文章 [由搬家工具导入] http://weblogs.asp.net/gunnarpeipman/archive/2009/05/19/n ...