search

Home  >  Q&A  >  body text

javascript - How to use the state obtained by ...mapGetters and ...mapState to operate in methods?

Can it only be displayed on the page? I know that I can use this.$store.state to obtain these states for operation

阿神阿神2792 days ago815

reply all(3)I'll reply

  • 巴扎黑

    巴扎黑2017-05-31 10:42:20

     ...mapState({
            a: function (state) {
              return state.A
            },
            b: function (state) {
              return state.b
            }
          })

    Just access this.a this.b directly in other methods

    reply
    0
  • 滿天的星座

    滿天的星座2017-05-31 10:42:20

    For example, ...mapState(['changePrePosition'])Just use this.changePrePosition()

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-31 10:42:20

    ...mapState(['value'])

    Use this.value to get the value, but modifying the value of state requires mutations

    reply
    0
  • Cancelreply