import { mapState } from 'vuex' import store from '@/store' //将vuex下的state数据混入全局变量中 let $uStoreKey = [] try { $uStoreKey = store.state ? Object.keys(store.state) : [] } catch (e) { //TODO handle the exception } module.exports = { created() { this.$u.vuex = (name, value) => { this.$store.commit('$uStore', { name, value }) } }, computed: { // 将vuex的state中的所有变量,全局混入mixin ...mapState($uStoreKey) } }