added exported httpClient for axios
This commit is contained in:
parent
94ec093a69
commit
d53f17ef3b
|
@ -0,0 +1,18 @@
|
||||||
|
import axios from 'axios'
|
||||||
|
|
||||||
|
class Service {
|
||||||
|
constructor(url) {
|
||||||
|
this.url = url
|
||||||
|
}
|
||||||
|
getFinanzerMain(token) {
|
||||||
|
return axios.get(this.url + "getFinanzerMain", {headers: {Token: token}})
|
||||||
|
|
||||||
|
}
|
||||||
|
login(loginData) {
|
||||||
|
return axios.post(this.url+'login', {...loginData})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const httpClient = new Service("http://192.168.5.118:5000/")
|
||||||
|
|
||||||
|
export default httpClient
|
|
@ -1,12 +1,10 @@
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import Vuex from 'vuex'
|
import Vuex from 'vuex'
|
||||||
import router from "@/router";
|
import router from "@/router";
|
||||||
import axios from 'axios'
|
import httpClient from "../plugins/restService";
|
||||||
|
|
||||||
Vue.use(Vuex)
|
Vue.use(Vuex)
|
||||||
|
|
||||||
const url = 'http://localhost:5000/'
|
|
||||||
|
|
||||||
export default new Vuex.Store({
|
export default new Vuex.Store({
|
||||||
state: {
|
state: {
|
||||||
user: {
|
user: {
|
||||||
|
@ -53,7 +51,7 @@ export default new Vuex.Store({
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log("loginData:", loginData)
|
console.log("loginData:", loginData)
|
||||||
commit('loginStart');
|
commit('loginStart');
|
||||||
axios.post(url+'login', {...loginData})
|
httpClient.login(loginData)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
localStorage.setItem('user', JSON.stringify({ username: response.data.username, accessToken: response.data.token, group: response.data.group}));
|
localStorage.setItem('user', JSON.stringify({ username: response.data.username, accessToken: response.data.token, group: response.data.group}));
|
||||||
commit('loginStop', null);
|
commit('loginStop', null);
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import TitleBar from "@/components/TitleBar";
|
import TitleBar from "@/components/TitleBar";
|
||||||
import axios from 'axios'
|
import httpClient from "../plugins/restService";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "FinanzerView",
|
name: "FinanzerView",
|
||||||
|
@ -31,24 +31,28 @@
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getUser() {
|
getUser() {
|
||||||
axios.get("http://localhost:5000/getFinanzerMain", {headers: {Token: this.$store.getters.getToken}})
|
httpClient.getFinanzerMain(this.$store.getters.getToken)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log(response.data)
|
console.log("ich bin hier. response: ", response.data)
|
||||||
for (let user in response.data) {
|
for (let user in response.data) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log(response.data[user])
|
console.log("user: ", user)
|
||||||
const lastId = this.users.length > 0 ? this.users[this.users.length - 1].id : 0
|
const lastId = this.users.length > 0 ? this.users[this.users.length - 1].id : 0
|
||||||
this.users.push({id: lastId + 1, username: response.data[user].username, firstname: response.data[user].firstname, lastname: response.data[user].lastname})
|
this.users.push({
|
||||||
}
|
id: lastId + 1,
|
||||||
// eslint-disable-next-line no-console
|
username: response.data[user].username,
|
||||||
console.log(this.users)
|
firstname: response.data[user].firstname,
|
||||||
})
|
lastname: response.data[user].lastname
|
||||||
|
})
|
||||||
|
}})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log("error: ", error.response.data.error)
|
console.log("error: ", error.response.data.error)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log("this.users: ", this.users)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue