平安校园
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

$u.mixin.js 696 B

3 months ago
1234567891011121314151617181920212223242526272829
  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. 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. }