123456789101112131415161718192021222324252627282930313233343536 |
- /*
- * @Author: PoJun
- * @Date: 2023-05-14 17:58:20
- * @LastEditors: PoJun
- * @LastEditTime: 2023-10-20 13:44:40
- * @Message: Nothing
- */
- import { mapState } from "vuex";
- import store from "@/store";
- // 尝试将用户在根目录中的store/index.js的vuex的state变量,全部加载到全局变量中
- let $uStoreKey = [];
- try {
- $uStoreKey = store.state ? Object.keys(store.state) : [];
- } catch (e) {
- console.log(e);
- }
- module.exports = {
- created() {
- // 将vuex方法挂在到$uv中, 方法的调用不能再页面的时候. 需要等方法挂载完毕
- // 使用方法为:如果要修改vuex的state中的user.name变量为"史诗" => this.$uv.vuex('user.name', '史诗')
- // 如果要修改vuex的state的version变量为1.0.1 => this.$uv.vuex('version', '1.0.1')
- this.$uv.vuex = (name, value) => {
- this.$store.commit("$uStore", {
- name,
- value,
- });
- };
- },
- computed: {
- // 将vuex的state中的所有变量,解构到全局混入的mixin中
- ...mapState($uStoreKey),
- },
- };
|