Home  >  Q&A  >  body text

javascript - After state is mapped to computed through mapState in vuex, how to write the original calculated properties?

import {mapState} from 'vuex'

export default {
  data(){
      return {
          oldData: 0
      }
  }
  computed: mapState({
    count: state => state.count,
    newData(){
       return this.oldData + 1;
    }
  })
}

Do you write it like this?

给我你的怀抱给我你的怀抱2684 days ago507

reply all(1)I'll reply

  • 巴扎黑

    巴扎黑2017-05-16 13:43:59

    import {mapState} from 'vuex'
    
    export default {
      data() {
        return {        //你这里少写了
            oldData: 0
        }
      }
      computed: {
        ...mapState(["count"]),
        newData(){
           return this.oldData + 1;
        }
      }
    }

    reply
    0
  • Cancelreply