在Vue3中,可以使用axios库来发送请求并携带cookie。首先,需要安装axios库:

npm install axios

然后,在发送请求时,可以通过axios的配置项来携带cookie。例如:

import axios from 'axios';

axios.get('/api/data', {
  withCredentials: true // 携带cookie
}).then(response => {
  console.log(response.data);
}).catch(error => {
  console.log(error);
});

其中,withCredentials配置项设置为true表示携带cookie。注意,服务器也需要设置Access-Control-Allow-Credentialstrue才能接收到携带cookie的请求。

vue3发送请求携带cookie

原文地址: https://www.cveoy.top/t/topic/bsSX 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录