$u.mixin.js 504 B

1234567891011121314151617181920212223242526
  1. import {
  2. mapState
  3. } from 'vuex'
  4. import store from '@/store'
  5. //将vuex下的state数据混入全局变量中
  6. let $uStoreKey = []
  7. try {
  8. $uStoreKey = store.state ? Object.keys(store.state) : []
  9. } catch (e) {
  10. //TODO handle the exception
  11. }
  12. module.exports = {
  13. created() {
  14. this.$u.vuex = (name, value) => {
  15. this.$store.commit('$uStore', {
  16. name,
  17. value
  18. })
  19. }
  20. },
  21. computed: {
  22. // 将vuex的state中的所有变量,全局混入mixin
  23. ...mapState($uStoreKey)
  24. }
  25. }