From 8891e81475abed7ea3759aea98000dbdda6466f0 Mon Sep 17 00:00:00 2001 From: Maxim Lyatsky Date: Wed, 2 May 2018 08:50:34 +0300 Subject: [PATCH] feat(core): add api layer for application --- build/webpack.dev.conf.js | 3 ++- config/index.js | 2 +- package.json | 3 ++- src/components/AddsList.vue | 2 ++ src/components/Login.vue | 30 +++++++++++++++++++++++++----- src/store/api.js | 3 +++ src/store/index.js | 26 ++++++++++++++++++++++++-- 7 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 src/store/api.js diff --git a/build/webpack.dev.conf.js b/build/webpack.dev.conf.js index 070ae22..500b2ca 100755 --- a/build/webpack.dev.conf.js +++ b/build/webpack.dev.conf.js @@ -42,7 +42,8 @@ const devWebpackConfig = merge(baseWebpackConfig, { quiet: true, // necessary for FriendlyErrorsPlugin watchOptions: { poll: config.dev.poll, - } + }, + disableHostCheck: true }, plugins: [ new webpack.DefinePlugin({ diff --git a/config/index.js b/config/index.js index bfdb3d7..e4d790a 100644 --- a/config/index.js +++ b/config/index.js @@ -14,7 +14,7 @@ module.exports = { // Various Dev Server settings host: '0.0.0.0', // can be overwritten by process.env.HOST - port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined + port: 82, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined autoOpenBrowser: false, errorOverlay: true, notifyOnErrors: true, diff --git a/package.json b/package.json index 14c14a2..bdb7dfe 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,8 @@ "dependencies": { "vue": "^2.5.2", "vue-router": "^3.0.1", - "vuex": "^3.0.1" + "vuex": "^3.0.1", + "axios": "^0.17.1" }, "devDependencies": { "autoprefixer": "^7.1.2", diff --git a/src/components/AddsList.vue b/src/components/AddsList.vue index 12c3545..55dad12 100644 --- a/src/components/AddsList.vue +++ b/src/components/AddsList.vue @@ -4,6 +4,8 @@
{{ item.name }}
+


+ Login diff --git a/src/components/Login.vue b/src/components/Login.vue index fa702f2..4c5ea01 100644 --- a/src/components/Login.vue +++ b/src/components/Login.vue @@ -3,6 +3,9 @@

Login page

{{ login }}
+
+ Something went wrong +
@@ -17,22 +20,39 @@ diff --git a/src/store/api.js b/src/store/api.js new file mode 100644 index 0000000..8d5d98a --- /dev/null +++ b/src/store/api.js @@ -0,0 +1,3 @@ +export default { + login: 'http://api.stud.hz/?action=login' +} diff --git a/src/store/index.js b/src/store/index.js index a6a52a0..4f67133 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1,5 +1,8 @@ import Vue from 'vue' import Vuex from 'vuex' +import axios from 'axios' + +import API from './api' Vue.use(Vuex) @@ -16,10 +19,16 @@ const Store = new Vuex.Store({ }, { id: '3', - name: 'test3' + name: 'test3' { + path: '/', + name: 'AddsList', + component: AddsList + }, } ], - addItem: {} + addItem: {}, + user: {}, + isAuth: false }, mutations: { updateAddsList (state, data) { @@ -27,6 +36,12 @@ const Store = new Vuex.Store({ }, updateAddItem (state, data) { state.addItem = data + }, + updateAuth (state, data) { + state.isAuth = data + }, + updateUser (state, data) { + state.user = data } }, actions: { @@ -50,6 +65,13 @@ const Store = new Vuex.Store({ }) context.commit('updateAddsList', context.state.addsList) + }, + login (context, params) { + return axios.post(API.login, params, {withCredentials: true}) + .then(responce => { + context.commit('updateUser', responce.data) + context.commit('updateAuth', true) + }) } } })