一吱殉、前端vue 中 axios簡單封裝
import axios from "axios";
const http = axios.create({
baseURL: '',
timeout: 1000 * 60 * 2,
withCredentials: true,
})
http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
export default http
二款侵、express 中設(shè)置
const express = require('express')
const cors = require('cors')
const app = express()
const corsOptions = {
origin:'http://localhost:8080', //axios中設(shè)置了withCredentials: true黎烈,這里origin需指定前端的具體網(wǎng)址
credentials: true, //允許攜帶cookie
}
app.use(cors(corsOptions))
app.listen(3000, () => {
console.log('http://localhost:3000')
})