zoukankan      html  css  js  c++  java
  • 2.vuex学习之state、mapState

    1.state状态对象管理器

       在store.js中

    import Vue from 'vue'
    import Vuex from 'vuex'
    
    Vue.use(Vuex)
    
    //访问状态对象
    const state = {
        count:1
    }
    
    
    export default new Vuex.Store({
        state
    })

    在App.vue文件中

    <template>
      <div id="app">
        
        <img src="./assets/logo.png">
        <h1>{{ msg}}</h1>
        <!--访问状态对象-->
        <div>state-->{{$store.state.count}}</div>
        <!--计算属性-->
        <h1>mapState 计算属性-->{{count}}</h1>
        
      </div>
    </template>
    
    <script>
    
    //vuex提供的辅助函数
    import {mapState} from 'vuex'
    export default {
      name: 'app',
      data () {
        return {
          msg: 'Welcome to Your Vue.js App'
        }
      },
      
      // computed:{
      //   count(){
      //     return  this.$store.state.count //this指的是store
      //   }
      // },
    
      // computed:mapState({
      //   count:state=>state.count++
      // })
      
      // 不对computed进行计算,count直接引进来
      computed:{
        ...mapState([
          'count'
        ])
      },
      //解决页面白屏问题
      mounted(){
        if(app.hasChildNodes()){
              loading.style.display="none";
              console.log(1)
           }else{
             console.log(app.childNodes)
           }
      },
    }
    </script>
    
    <style>
    #app {
      font-family: 'Avenir', Helvetica, Arial, sans-serif;
      -webkit-font-smoothing: antialiased;
      -moz-osx-font-smoothing: grayscale;
      text-align: center;
      color: #2c3e50;
      margin-top: 60px;
    }
    
    h1, h2 {
      font-weight: normal;
    }
    
    ul {
      list-style-type: none;
      padding: 0;
    }
    
    li {
      display: inline-block;
      margin: 0 10px;
    }
    
    a {
      color: #42b983;
    }
    </style>
  • 相关阅读:
    张一鸣:平常心做非常事|字节跳动9周年演讲全文
    实验二:分词
    helm部署EFK收集应用日志,ingress-nginx日志解析。
    Terraform
    Windows 11 下载
    Kubernetes Pod中容器的Liveness、Readiness和Startup探针
    Kubernetes使用Keda进行弹性伸缩
    K8s 部署 Prometheus + Grafana
    CSDN & 博客园
    zipkin,pinpoint和skywalking对比
  • 原文地址:https://www.cnblogs.com/tw6668/p/9107011.html
Copyright © 2011-2022 走看看