Skip to content

Commit 065a7c6

Browse files
committed
added axios as globally available plugin
1 parent 5a9abec commit 065a7c6

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"lint": "vue-cli-service lint"
99
},
1010
"dependencies": {
11+
"axios": "^0.20.0",
1112
"core-js": "^3.6.5",
1213
"tailwindcss": "^1.8.10",
1314
"vee-validate": "^3.3.11",

frontend/src/main.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Vue from 'vue';
22
import { ValidationProvider, ValidationObserver, extend } from 'vee-validate/dist/vee-validate.full.esm';
3+
import http from './plugins/http';
34
import App from './App.vue';
45
import router from './router';
56
import store from './store';
@@ -12,6 +13,8 @@ extend('validPassword', validPassword);
1213

1314
Vue.config.productionTip = false;
1415

16+
Vue.use(http);
17+
1518
new Vue({
1619
router,
1720
store,

frontend/src/plugins/http.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import Axios from 'axios';
2+
import Vue from 'vue';
3+
4+
function createAxiosInstance(baseURL) {
5+
return Axios.create({
6+
baseURL,
7+
headers: {
8+
'Content-Type': 'application/json',
9+
Authorization: `Bearer ${localStorage.token}`,
10+
},
11+
});
12+
}
13+
14+
const axiosInstance = createAxiosInstance('http://localhost:8080');
15+
16+
export default {
17+
install() {
18+
Vue.prototype.$http = axiosInstance;
19+
},
20+
};

frontend/yarn.lock

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1870,6 +1870,13 @@ aws4@^1.8.0:
18701870
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.10.1.tgz#e1e82e4f3e999e2cfd61b161280d16a111f86428"
18711871
integrity sha512-zg7Hz2k5lI8kb7U32998pRRFin7zJlkfezGJjUc2heaD4Pw2wObakCDVzkKztTm/Ln7eiVvYsjqak0Ed4LkMDA==
18721872

1873+
axios@^0.20.0:
1874+
version "0.20.0"
1875+
resolved "https://registry.yarnpkg.com/axios/-/axios-0.20.0.tgz#057ba30f04884694993a8cd07fa394cff11c50bd"
1876+
integrity sha512-ANA4rr2BDcmmAQLOKft2fufrtuvlqR+cXNNinUmvfeSNCOF98PZL+7M/v1zIdGo7OLjEA9J2gXJL+j4zGsl0bA==
1877+
dependencies:
1878+
follow-redirects "^1.10.0"
1879+
18731880
babel-eslint@^10.1.0:
18741881
version "10.1.0"
18751882
resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-10.1.0.tgz#6968e568a910b78fb3779cdd8b6ac2f479943232"
@@ -4076,7 +4083,7 @@ flush-write-stream@^1.0.0:
40764083
inherits "^2.0.3"
40774084
readable-stream "^2.3.6"
40784085

4079-
follow-redirects@^1.0.0:
4086+
follow-redirects@^1.0.0, follow-redirects@^1.10.0:
40804087
version "1.13.0"
40814088
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.0.tgz#b42e8d93a2a7eea5ed88633676d6597bc8e384db"
40824089
integrity sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA==

0 commit comments

Comments
 (0)