vue的getters属性相当于计算属性,可以对数据进行二次处理
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script src="vue.js"></script>
<script src="vuex.js"></script>
</head>
<body>
<div id="box">
<button @click="add">{{count}}</button>
</div>
</body>
<script>
var box=new Vue({
el:"#box",
data:{
},
computed:Vuex.mapGetters({
count:"$count"
}),
methods:{
add:function(){
this.$store.commit("add");
}
},
store:new Vuex.Store({
state:{
count:0
},
mutations:{
add:function(state){
state.count++
}
},
getters:{
$count:function(state){
return "$"+state.count
}
}//相当于计算属性,可以对数据进行二次的处理
})
})
</script>
</html>