Skip to content

Instantly share code, notes, and snippets.

@abishekrsrikaanth
Last active July 31, 2019 13:30
Show Gist options
  • Save abishekrsrikaanth/e20f8fa19e9187c31b1ecbd4f2f521f9 to your computer and use it in GitHub Desktop.
Save abishekrsrikaanth/e20f8fa19e9187c31b1ecbd4f2f521f9 to your computer and use it in GitHub Desktop.
import Vue from 'vue';
import Auth from '../mixins/user-auth';
import makeUserStore from '../store/user';
new Vue({
mixins: [Auth],
el: '.auth-wrapper',
store: makeUserStore(),
async mounted() {
let user = await this.__getUser();
this.$store.commit('setUser', user.data);
}
});
<!DOCTYPE html>
<html lang="en">
<!-- begin::Head -->
<head>
<meta charset="utf-8"/>
</head>
<body>
<div class='auth-wrapper'></div>
<div class='product-wrapper'>@{{userObject.id}}</div>
<script src="{{mix('js/auth.js')}}"></script>
<script src="{{mix('js/product.js')}}"></script>
</body
</html>
import Vue from 'vue';
import Request from 'greenlyst-ui/src/mixins/request';
import makeUserStore from '../../../store/user';
import {mapGetters} from 'vuex';
new Vue({
el: '.product-wrapper',
store: makeUserStore(),
computed: {
...mapGetters(['userObject'])
}
});
import Vuex from 'vuex';
export default function () {
return new Vuex.Store({
state: {
user: {}
},
getters: {
userObject: state => {
return state.user;
}
},
mutations: {
setUser(state, userObj) {
state.user = userObj;
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment