平安校园
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

31 satır
792 B

  1. // $u.mixin.js
  2. import { mapState } from 'vuex'
  3. import store from "@/store"
  4. // 尝试将用户在根目录中的store/index.js的vuex的state变量,全部加载到全局变量中
  5. let $uStoreKey = [];
  6. try {
  7. $uStoreKey = store.state ? Object.keys(store.state) : [];
  8. } catch (e) {
  9. }
  10. module.exports = {
  11. mounted() {
  12. // 将vuex方法挂在到$u中
  13. // 使用方法为:如果要修改vuex的state中的user.name变量为"史诗" => this.$u.vuex('user.name', '史诗')
  14. // 如果要修改vuex的state的version变量为1.0.1 => this.$u.vue x('version', '1.0.1')
  15. this.$u.vuex = (name, value) => {
  16. this.$store.commit('$uStore', {
  17. name,
  18. value
  19. })
  20. }
  21. },
  22. computed: {
  23. // 将vuex的state中的所有变量,解构到全局混入的mixin中
  24. ...mapState($uStoreKey)
  25. }
  26. }