安装@nuxtjs/axios
https://axios.nuxtjs.org/setup
bash
npm install @nuxtjs/axios
nuxt.config.js
javascript
export default {
modules: ['@nuxtjs/axios']
}
mock数据
没有账号直接输入账号、密码登录会自动创建,没有修改密码的入口需要保存好账号密码。
使用
https://axios.nuxtjs.org/usage
asyncData
javascript
async asyncData({ $axios }) {
const ip = await $axios.$get('http://icanhazip.com')
return { ip }
}
methods/created/mounted/etc
javascript
methods: {
async fetchSomething() {
const ip = await this.$axios.$get('http://icanhazip.com')
this.ip = ip
}
}