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