Nuxt项目中使用axios
生活随笔
收集整理的這篇文章主要介紹了
Nuxt项目中使用axios
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
把nuxtjs-axios模塊添加到項目
yarn add @nuxtjs/axios // 使用yarn來安裝模塊npm install @nuxtjs/axios // 使用npm來安裝模塊注:不同的包管理器,要使用不同的命令
配置nuxt.config.js
簡單使用
modules: [ '@nuxtjs/axios' ],如果這步完成,可以在項目中方法使用console.log(this) ,這時候可以看到該對象中有$axios屬性了
如果你想使用代理可以這樣寫
axios: {proxy: true,// prefix: '/api/',credentials: true// See https://github.com/nuxt-community/axios-module#options},proxy: {'/api/': {target: 'https://h5api.zhefengle.cn', //這個網站是開源的可以請求到數據的pathRewrite: {'^/api/': '/',changeOrigin: true}}},使用
let that=this; this.$axios.get("/api/index.html").then(res=>{ alert(res.data.code); });總結
以上是生活随笔為你收集整理的Nuxt项目中使用axios的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Go语言在Linux环境下输出彩色字符
- 下一篇: Go实现希尔排序