美文网首页
其他组件调用

其他组件调用

作者: 嗯哼_3395 | 来源:发表于2018-07-07 16:04 被阅读0次
<!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>
          <veb></veb>
      </div>
</body>
      <script>
     //其他组件的访问
      // Vue.component("veb",{
      //      template:`<button>{{$store.state.count}}</button>`,

      // })
      
      Vue.component("veb",{
           template:`<button>{{count}}</button>`,
           computed:{
              count:function(){
                  return this.$store.state.count  //假设{{name}},在里面的钩子函数都是通过this去访问的
              }
           }

      })

       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>

相关文章

网友评论

      本文标题:其他组件调用

      本文链接:https://www.haomeiwen.com/subject/whtguftx.html