Skip to content

Instantly share code, notes, and snippets.

@hex-ci
Created December 20, 2017 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hex-ci/b8737ce127256d46115e85e387f3e73e to your computer and use it in GitHub Desktop.
Save hex-ci/b8737ce127256d46115e85e387f3e73e to your computer and use it in GitHub Desktop.
Axios 访问 Vue.js 组件的实例
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