essay-org / essay

personalise blog system

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

proxy如何解决跨域请求呢?

zhilizhui opened this issue · comments

你好,我想在本地进行开发,但是后台不想设置请求头,我如果要在前端设置代理,要怎么设置nuxt.config.js呢 ?

commented

@zhilizhui

  1. yarn add @nuxtjs/axios 或者 npm install @nuxtjs/axios
  2. 配置文件添加
axios: {
  proxy: true
},
proxy: {
  '/api': 'http://api.example.com'
},
modules: ['@nuxtjs/axios']
  1. 使用
// http://127.0.0.1:3000/test 代理到 http://api.example.com/test
this.$axios.$get('/api/test').then(data => {

})
commented

最简单的办法是把后端打一顿,这样他就配置了

commented

哈哈哈,皮