zhengwei1949 / myblog

个人博客
10 stars 6 forks source link

vuex理解 #152

Open zhengwei1949 opened 5 years ago

zhengwei1949 commented 5 years ago
<template>
  <div id="app">
    {{list}} -- {{a}} -- {{aa}}
    <hr>
    <button @click="sendData">点击发送ajax</button>
  </div>
</template>
<script>
import {mapState,mapGetters,mapMutations,mapActions} from 'vuex'
export default {
  methods:{
    ...mapMutations({
      add:'add'
    }),
    async sendData(){
      this.add(200)
      try{
        const response = await this.$http.get('interface/blogs/all')
        const data = response.data 
        console.log(data);
      }catch(err){

      }
    }
  },
  computed:{
    ...mapState({
      list:'list',
      a:'a'
    }),
    ...mapGetters({
      aa:'aa'
    })
  }
}
</script>
<style>

</style>