美文网首页
轻量级 vux

轻量级 vux

作者: Allan要做活神仙 | 来源:发表于2020-08-19 10:35 被阅读0次

2020-08-19

关键:new 一个实例 + mixin computed

store.js

// 全局状态存储
export const state = new Vue({
    data: () => ({
        userType: -1
    }),
});

index.js

import {state} from './store';
// 组件通信方案二:全局公用状态存储 store.js
Vue.mixin({
    computed: {
        state: () => ({
            ...state,
        }),
    },
});

app.vue

import {state} from './store';
// state 赋值
state.data = res.data;

A-Component

// 取值
this.state.data

相关文章

网友评论

      本文标题:轻量级 vux

      本文链接:https://www.haomeiwen.com/subject/xqdrjktx.html