前端跨域简单的配置

63 阅读1分钟

以下是vue文件中添加文件代理服务器,文件名:vue.config.js

module.exports = { lintOnSave: false, devServer: { proxy: { '/api': { ws: true, target: 'http://localhost:3000', changeOrigin: true, pathRewrite: { '^/api': '/' } } } } }

以下是cors解决跨域,在后台文件中

npm i cors (安装cors)

var cors = require('cors'); (引用cors)

app.use(cors('Access-Control-Allow-Origin', '*')) (允许所有访问)