axios: baseURL

This commit is contained in:
2023-02-10 14:42:11 +01:00
parent 446698b832
commit 580e109dda
7 changed files with 86 additions and 98 deletions
-45
View File
@@ -1,45 +0,0 @@
import { defineComponent } from 'vue';
import { useStore } from '../store';
import axios from 'axios';
export default defineComponent({
setup() {
return {
store: useStore(),
};
},
data() {
return {
API_URL: import.meta.env.PROD ? import.meta.env.VITE_API_URL : import.meta.env.VITE_API_URL_DEV,
};
},
methods: {
async loadData() {
try {
this.store.dataState = 'LOADING';
const data = (
await axios.get(`${this.API_URL}/api/getSceneries?time=${Date.now()}`, {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.store.token}`,
},
})
).data;
this.store.backupList = JSON.parse(JSON.stringify(data));
this.store.stationList = data;
this.store.unsavedChanges = false;
this.store.changeList = [];
this.store.dataState = 'LOADED';
} catch (error) {
this.store.dataState = 'ERROR';
this.store.token = '';
this.store.isAuthorized = false;
}
},
},
});