Created
December 20, 2017 03:37
-
-
Save hex-ci/b8737ce127256d46115e85e387f3e73e to your computer and use it in GitHub Desktop.
Axios 访问 Vue.js 组件的实例
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vue from 'vue' | |
import App from './App' | |
import axios from 'axios' | |
const plugins = { | |
install(Vue) { | |
Vue.prototype.$fetch = function(url, options) { | |
return axios(url, options) | |
.then(response => { | |
console.log(this) | |
}) | |
.catch(error => { | |
console.log(this) | |
}) | |
} | |
} | |
} | |
Vue.use(plugins); | |
new Vue({ | |
el: '#app', | |
render: (h) => h(App) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment