Skip to content

Commit 7f84f29

Browse files
add axios
1 parent cf8286b commit 7f84f29

File tree

4 files changed

+92
-1
lines changed

4 files changed

+92
-1
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"@vue/eslint-config-standard": "^5.1.2",
3737
"@vue/eslint-config-typescript": "^7.0.0",
3838
"@vue/test-utils": "^1.0.3",
39+
"axios": "^0.18.0",
3940
"chai": "^4.1.2",
4041
"eslint": "^6.7.2",
4142
"eslint-plugin-import": "^2.20.2",
@@ -46,6 +47,7 @@
4647
"sass": "~1.32.0",
4748
"sass-loader": "^10.0.0",
4849
"typescript": "~4.1.5",
50+
"vue-cli-plugin-axios": "~0.0.4",
4951
"vue-cli-plugin-vuetify": "~2.4.3",
5052
"vue-template-compiler": "^2.6.11",
5153
"vuetify-loader": "^1.7.0"

src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Vue from 'vue'
2+
import './plugins/axios'
23
import App from './App.vue'
34
import './registerServiceWorker'
45
import router from './router'

src/plugins/axios.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
'use strict'
2+
3+
import Vue from 'vue'
4+
import axios from 'axios'
5+
6+
// Full config: https://github.com/axios/axios#request-config
7+
// axios.defaults.baseURL = process.env.baseURL || process.env.apiUrl || '';
8+
// axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
9+
// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
10+
11+
const config = {
12+
// baseURL: process.env.baseURL || process.env.apiUrl || ""
13+
// timeout: 60 * 1000, // Timeout
14+
// withCredentials: true, // Check cross-site Access-Control
15+
}
16+
17+
const _axios = axios.create(config)
18+
19+
_axios.interceptors.request.use(
20+
function (config) {
21+
// Do something before request is sent
22+
return config
23+
},
24+
function (error) {
25+
// Do something with request error
26+
return Promise.reject(error)
27+
}
28+
)
29+
30+
// Add a response interceptor
31+
_axios.interceptors.response.use(
32+
function (response) {
33+
// Do something with response data
34+
return response
35+
},
36+
function (error) {
37+
// Do something with response error
38+
return Promise.reject(error)
39+
}
40+
)
41+
42+
Plugin.install = function (Vue, options) {
43+
Vue.axios = _axios
44+
window.axios = _axios
45+
Object.defineProperties(Vue.prototype, {
46+
axios: {
47+
get () {
48+
return _axios
49+
}
50+
},
51+
$axios: {
52+
get () {
53+
return _axios
54+
}
55+
}
56+
})
57+
}
58+
59+
Vue.use(Plugin)
60+
61+
export default Plugin

yarn.lock

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2150,6 +2150,14 @@ aws4@^1.8.0:
21502150
resolved "https://registry.nlark.com/aws4/download/aws4-1.11.0.tgz#d61f46d83b2519250e2784daf5b09479a8b41c59"
21512151
integrity sha1-1h9G2DslGSUOJ4Ta9bCUeai0HFk=
21522152

2153+
axios@^0.18.0:
2154+
version "0.18.1"
2155+
resolved "https://registry.npmmirror.com/axios/download/axios-0.18.1.tgz?cache=0&sync_timestamp=1633067756491&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2Faxios%2Fdownload%2Faxios-0.18.1.tgz#ff3f0de2e7b5d180e757ad98000f1081b87bcea3"
2156+
integrity sha1-/z8N4ue10YDnV62YAA8Qgbh7zqM=
2157+
dependencies:
2158+
follow-redirects "1.5.10"
2159+
is-buffer "^2.0.2"
2160+
21532161
babel-code-frame@^6.22.0:
21542162
version "6.26.0"
21552163
resolved "https://registry.npm.taobao.org/babel-code-frame/download/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b"
@@ -3534,6 +3542,13 @@ debug@3.2.6:
35343542
dependencies:
35353543
ms "^2.1.1"
35363544

3545+
debug@=3.1.0:
3546+
version "3.1.0"
3547+
resolved "https://registry.nlark.com/debug/download/debug-3.1.0.tgz?cache=0&sync_timestamp=1625374632845&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fdebug%2Fdownload%2Fdebug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261"
3548+
integrity sha1-W7WgZyYotkFJVmuhaBnmFRjGcmE=
3549+
dependencies:
3550+
ms "2.0.0"
3551+
35373552
debug@^3.1.0, debug@^3.1.1, debug@^3.2.6, debug@^3.2.7:
35383553
version "3.2.7"
35393554
resolved "https://registry.nlark.com/debug/download/debug-3.2.7.tgz?cache=0&sync_timestamp=1625374735764&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fdebug%2Fdownload%2Fdebug-3.2.7.tgz#72580b7e9145fb39b6676f9c5e5fb100b934179a"
@@ -4766,6 +4781,13 @@ flush-write-stream@^1.0.0:
47664781
inherits "^2.0.3"
47674782
readable-stream "^2.3.6"
47684783

4784+
follow-redirects@1.5.10:
4785+
version "1.5.10"
4786+
resolved "https://registry.nlark.com/follow-redirects/download/follow-redirects-1.5.10.tgz?cache=0&sync_timestamp=1631622163078&other_urls=https%3A%2F%2Fregistry.nlark.com%2Ffollow-redirects%2Fdownload%2Ffollow-redirects-1.5.10.tgz#7b7a9f9aea2fdff36786a94ff643ed07f4ff5e2a"
4787+
integrity sha1-e3qfmuov3/NnhqlP9kPtB/T/Xio=
4788+
dependencies:
4789+
debug "=3.1.0"
4790+
47694791
follow-redirects@^1.0.0:
47704792
version "1.14.4"
47714793
resolved "https://registry.nlark.com/follow-redirects/download/follow-redirects-1.14.4.tgz?cache=0&sync_timestamp=1631622163078&other_urls=https%3A%2F%2Fregistry.nlark.com%2Ffollow-redirects%2Fdownload%2Ffollow-redirects-1.14.4.tgz#838fdf48a8bbdd79e52ee51fb1c94e3ed98b9379"
@@ -5736,7 +5758,7 @@ is-buffer@^1.1.5:
57365758
resolved "https://registry.npm.taobao.org/is-buffer/download/is-buffer-1.1.6.tgz?cache=0&sync_timestamp=1604429584981&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fis-buffer%2Fdownload%2Fis-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be"
57375759
integrity sha1-76ouqdqg16suoTqXsritUf776L4=
57385760

5739-
is-buffer@~2.0.3:
5761+
is-buffer@^2.0.2, is-buffer@~2.0.3:
57405762
version "2.0.5"
57415763
resolved "https://registry.npm.taobao.org/is-buffer/download/is-buffer-2.0.5.tgz?cache=0&sync_timestamp=1604429584981&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fis-buffer%2Fdownload%2Fis-buffer-2.0.5.tgz#ebc252e400d22ff8d77fa09888821a24a658c191"
57425764
integrity sha1-68JS5ADSL/jXf6CYiIIaJKZYwZE=
@@ -10099,6 +10121,11 @@ vue-class-component@^7.2.3:
1009910121
resolved "https://registry.npm.taobao.org/vue-class-component/download/vue-class-component-7.2.6.tgz#8471e037b8e4762f5a464686e19e5afc708502e4"
1010010122
integrity sha1-hHHgN7jkdi9aRkaG4Z5a/HCFAuQ=
1010110123

10124+
vue-cli-plugin-axios@~0.0.4:
10125+
version "0.0.4"
10126+
resolved "https://registry.nlark.com/vue-cli-plugin-axios/download/vue-cli-plugin-axios-0.0.4.tgz#29d4eb48275c7fe15b92e1fd5d95fbe2a966436f"
10127+
integrity sha1-KdTrSCdcf+FbkuH9XZX74qlmQ28=
10128+
1010210129
vue-cli-plugin-vuetify@~2.4.3:
1010310130
version "2.4.3"
1010410131
resolved "https://registry.npmmirror.com/vue-cli-plugin-vuetify/download/vue-cli-plugin-vuetify-2.4.3.tgz?cache=0&sync_timestamp=1633534211244&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2Fvue-cli-plugin-vuetify%2Fdownload%2Fvue-cli-plugin-vuetify-2.4.3.tgz#68a893642b354ed8d534e4a9bc63d0728a8987ac"

0 commit comments

Comments
 (0)