核心提示:vuex储存数据2.0的写法详解import Vuex from vuex //最上面要写上这一行 methods:{ setData: function(){ this.$store.dis...
vuex储存数据2.0的写法详解
import Vuex from 'vuex' //最上面要写上这一行 methods:{ setData: function(){ this.$store.dispatch('SET_NAME', this.name); //在一个方法里面,这就能将this.name存起来 this.$store.dispatch('SET_OLDPRICE', this.oldPrice); }, }, computed: Vuex.mapGetters({ name: 'getName', oldPrice: 'getOldPrice', }), this.name = this.$store.state.getName //获取