Skip to content

Instantly share code, notes, and snippets.

@arunredhu
arunredhu / http-client.js
Last active February 10, 2021 15:58
Http client for Vue.js application
import axios from 'axios';
/** Default config for axios instance */
let config = {
baseURL: 'http://localhost:3000/'
};
/** Creating the instance for axios */
const httpClient = axios.create(config);
@arunredhu
arunredhu / user-data.js
Created May 18, 2019 17:41
State management in large scale Vue.js application
import { reflectKeys } from '@/app/shared/services';
import { fetchUsers } from '../services';
/** Initial state */
const initialState = {
loading: false,
data: null,
error: null
};
import { usersData } from './shared/state';
export default {
modules: {
usersData
}
};
import Vue from 'vue';
import Vuex from 'vuex';
import { usersState } from './users';
Vue.use(Vuex);
export default new Vuex.Store({
state: {},
mutations: {},
@arunredhu
arunredhu / vue-error-handler.js
Last active March 18, 2020 13:43
Global error handler
import Vue from 'vue';
Vue.config.errorHandler = (err, vm, info) => {
// err: error trace
// vm: component in which error occured
// info: Vue specific error information such as lifecycle hooks, events etc.
// TODO: Perform any custom logic or log to server
};
window.onerror = function(message, source, lineno, colno, error) {
// TODO: write any custom logic or logs the error
};
export default {
name: "app-user-list",
created() {
this.$store.dispatch(actionsTypes.FETCH_USER_DATA);
},
errorCaptured(err, vm, info) {
// err: error trace
// vm: component in which error occured
<template>
<div>
<slot
v-if="err"
name="error"
v-bind:err="err"
v-bind:vm="vm"
v-bind:info="info"
>Something went wrong</slot>
<slot v-else></slot>
<template>
<div class="user-list">
<error-boundary>
<app-user-item/>
</error-boundary>
</div>
</template>