$u.mixin.js 445 B

1234567891011121314151617181920212223
  1. import { mapState } from 'vuex'
  2. import store from "@/store"
  3. // 尝试将用户在根目录中的store/index.js的vuex的state变量,全部加载到全局变量中
  4. let $uStoreKey = [];
  5. try{
  6. $uStoreKey = store.state ? Object.keys(store.state) : [];
  7. }catch(e){
  8. }
  9. module.exports = {
  10. created() {
  11. this.$u.vuex = (name, value) => {
  12. this.$store.commit('$uStore', {
  13. name,value
  14. })
  15. }
  16. },
  17. computed: {
  18. ...mapState($uStoreKey)
  19. }
  20. }