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