vue跨域代理配置


實際:http://a.com/b.php
代理:http://localhost/b.php
配置config/index.js

proxyTable: {
    '/api': {
        target:'http://a.com',
        changeOrigin: true,
         pathRewrite: {
          '^/api': '/'
        }
    } 
}

在main.js中:

import axios from 'axios'
Vue.prototype.axios = axios
axios.defaults.baseURL = '/api'

在組件中使用:

this.axios.get('/n.php').then((data) => {
    // 處理數據
})

僅限於開發環境,生產環境仍然需要服務端設置允許跨域


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM