vuex icon indicating copy to clipboard operation
vuex copied to clipboard

feat: useXXX helpers (issue #1725)

Open lukeJEdwards opened this issue 3 years ago • 0 comments

The useXXX helpers are not meant to replace the mapXXX helper but to bring compatibility to the setup() function when using the composition API as seen in issue #1725.

Basic usage:

import { useState } from "vuex";

export default {
  setup() {

    const { count } = useState(["count"])

    return {
      count
    }
  }
import { useState } from 'vuex'

export default {
  setup() {
    return {
      ...useState(['count'])
    }
  }
}

Giving a property an alias:

import { useState } from 'vuex'
export default {
  setup() {
    return {
      ...useState({ countAlias: 'count' })
    }
  }
}

Using namespaced modules:

import { useState } from 'vuex'
export default {
  setup() {
    return {
      ...useState('moduleB', [ 'count' ])
    }
  }
}

lukeJEdwards avatar Mar 23 '21 09:03 lukeJEdwards