全局变量store+computed接收数据
<!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 store=new Vuex.Store({
state:{
count:0//相当于data数据
},
mutations:{
add:function(state){
state.count++
}
}
})
var box=new Vue({
el:"#box",
data:{
},
//接收值
computed:{
count:function(){
return store.state.count
}
},
methods:{
add:function(){
store.commit("add");
}
}
})
</script>
</html>