Vue“全家桶”【一】--Vuex
快速导航 Vuex中的 State Vuex中的 Mutation Vuex中的 Action Vuex中的 Getter Vuex中的 State 1、State提供唯一的公共数据源,所有的共享的数据都要统一放在Store中的State中进行存储 const store = new Vuex.Store({ state:{ count:0 } }) 2、组件访问State中数据: 第一种方式this.$store.state.全局数据名称 < template > < div class = "hello" > < ! -- 在template中 this 可以省略 -- > < h1 > { { $store . state . count } } < / h1 > < / div > < / template > 第二种方式 从 vuex中按需导入mapState 函数 // 从 vuex中按需导入mapState 函数 < script > import { mapState } from 'vuex' export default { data ( ) { return { } } , computed : { ... mapState ( [ 'count' ] ) } } < / script > 如何使用 mapState, 直接使用 < template > <