NUXT中使用自带axios


在nuxt.config.js中作如下配置

modules: [
    // Doc: https://github.com/nuxt-community/axios-module#usage
    '@nuxtjs/axios'
  ],
  /*
  ** Axios module configuration
  */
  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
      }    
    }
  },

使用的时候如下(一定要加this关键字,axios前面的$不能丢)

mounted() {
        this.$axios.get("/index.html").then(res=>{
            console.log(res)
        })
    },

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM