Skip to content

Commit 94ad765

Browse files
committed
Edited README & Fixed tslint errors & bump cli version to beta 7
1 parent 68b61c1 commit 94ad765

File tree

11 files changed

+100
-9
lines changed

11 files changed

+100
-9
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
**VueJS Typescript with Vuex support using the Vue CLI 3**
2+
3+
Made from this great tutorial: https://codeburst.io/vuex-and-typescript-3427ba78cfa8

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
},
2020
"devDependencies": {
2121
"@types/jest": "^22.0.1",
22-
"@vue/cli-plugin-babel": "^3.0.0-beta.6",
23-
"@vue/cli-plugin-typescript": "^3.0.0-beta.6",
24-
"@vue/cli-plugin-unit-jest": "^3.0.0-beta.6",
25-
"@vue/cli-service": "^3.0.0-beta.6",
22+
"@vue/cli-plugin-babel": "^3.0.0-beta.7",
23+
"@vue/cli-plugin-typescript": "^3.0.0-beta.7",
24+
"@vue/cli-plugin-unit-jest": "^3.0.0-beta.7",
25+
"@vue/cli-service": "^3.0.0-beta.7",
2626
"@vue/test-utils": "^1.0.0-beta.10",
2727
"babel-core": "^7.0.0-0",
2828
"node-sass": "^4.7.2",

src/components/Profile.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,16 @@
2222
2323
@Component
2424
export default class HelloWorld extends Vue {
25+
@State('profile') profile: ProfileState;
26+
@Action('fetchData', {namespace}) fetchData: any;
27+
@Getter('fullName', {namespace}) fullName: string;
2528
2629
@Prop() private msg!: string;
2730
2831
constructor() {
2932
super();
3033
}
3134
32-
@State('profile') profile: ProfileState;
33-
@Action('fetchData', {namespace}) fetchData: any;
34-
@Getter('fullName', {namespace}) fullName: string;
35-
3635
mounted() {
3736
// fetching data as soon as the component's been mounted
3837
this.fetchData();

src/store/profile/actions.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
import { ActionTree } from 'vuex';
3+
import axios from 'axios';
4+
import { ProfileState, User } from './types';
5+
import { RootState } from '../types';
6+
7+
8+
export const actions: ActionTree<ProfileState, RootState> = {
9+
fetchData({ commit }): any {
10+
axios({
11+
url: 'https://next.json-generator.com/api/json/get/41AeRPqnE',
12+
}).then((response) => {
13+
const payload: User = response && response.data;
14+
commit('profileLoaded', payload);
15+
}, (error) => {
16+
console.log(error);
17+
commit('profileError');
18+
});
19+
},
20+
};

src/store/profile/getters.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { GetterTree } from 'vuex';
2+
import { ProfileState } from './types';
3+
import { RootState } from '../types';
4+
5+
export const getters: GetterTree<ProfileState, RootState> = {
6+
fullName(state): string {
7+
const { user } = state;
8+
console.log('user', user);
9+
const firstName = (user && user.firstName) || '';
10+
const lastName = (user && user.lastName) || '';
11+
return `${firstName} ${lastName}`;
12+
},
13+
};

src/store/profile/index.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Module } from 'vuex';
2+
import { getters } from './getters';
3+
import { actions } from './actions';
4+
import { mutations } from './mutations';
5+
import { ProfileState } from './types';
6+
import { RootState } from '../types';
7+
8+
export const state: ProfileState = {
9+
user: undefined,
10+
error: false,
11+
};
12+
13+
const namespaced: boolean = true;
14+
15+
export const profile: Module<ProfileState, RootState> = {
16+
namespaced,
17+
state,
18+
getters,
19+
actions,
20+
mutations,
21+
};

src/store/profile/mutations.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { MutationTree } from 'vuex';
2+
import { ProfileState, User } from './types';
3+
4+
export const mutations: MutationTree<ProfileState> = {
5+
profileLoaded(state, payload: User) {
6+
state.error = false;
7+
state.user = payload;
8+
},
9+
profileError(state) {
10+
state.error = true;
11+
state.user = undefined;
12+
},
13+
};

src/store/profile/types.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
export interface User {
3+
firstName: string;
4+
lastName: string;
5+
email: string;
6+
phone?: string;
7+
}
8+
9+
export interface ProfileState {
10+
user?: User;
11+
error: boolean;
12+
}

src/store/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface RootState {
2+
version: string;
3+
}

tslint.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"ordered-imports": false,
1111
"object-literal-sort-keys": false,
1212
"no-consecutive-blank-lines": false,
13-
"no-console": [false]
13+
"no-console": [false],
14+
"member-access": [true, "no-public"]
1415
}
1516
}

0 commit comments

Comments
 (0)