根实例

2018-07-07  本文已影响0人  嗯哼_3395
<!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">{{$store.state.count}}</button>
    </div>
</body>
    <script>
       var box=new Vue({
          el:"#box",
          data:{
              
          },
          store:new Vuex.Store({
             state:{
                 count:0
             },
             mutations:{
                add:function(state){
                    state.count++
                }
             }
          }),
          methods:{
              add:function(){
                  this.$store.commit("add")
              }
          }
       })

    </script>
</html>
上一篇 下一篇

猜你喜欢

热点阅读