mirror of https://github.com/sundowndev/http.git
670 B
670 B
Usage
Page Components
For asyncData
and fetch
you can access instance from context:
async asyncData({ $http }) {
const ip = await $http.get('http://icanhazip.com').text()
return { ip }
}
Component methods
Where you have access to this
, you can use this.$http
:
methods: {
async fetchSomething() {
const ip = await this.$http.get('http://icanhazip.com').text()
this.ip = ip
}
}
Store
For store action you can also use this.$http
:
// In store
{
actions: {
async getIP ({ commit }) {
const ip = await this.$http.get('http://icanhazip.com').text()
commit('SET_IP', ip)
}
}
}