vue 踩坑记录

本地开发没有cookie 解决方案
在这里插入图片描述
设置代理,并把changeOrigin设为true
proxy的changeOrigin如果设置为false:请求头中host仍然是浏览器发送过来的host;
如果设置成true:发送请求头中host会设置成target。

在这里插入图片描述
允许axios请求携带cookie等凭证

避坑:vite Component provided template option but runtime compilation is not supported in this…

This worked for me in vite.config.js
export default defineConfig({ 
        define: { "process.env": {} }, 
        plugins: [vue()], 
        resolve: { alias: { "vue": "vue/dist/vue.esm-bundler.js" } } })  // 这里是重点

antd 主题色更换踩坑 参考https://www.icode9.com/content-4-524054.html

vue3 vite 不能使用require 的替代方案
方案一:

 const getUrl=(url)=>{
        return new URL(url,import.meta.url).href;
        }
// 使用
const imgsrc = getUrl('../assets/images/logo.png');

或页面中直接使用

 <img :src="getUrl('../assets/images/logo.png')" style="width: 200px">

方案二:

// 方案解析:通过import.meta.globEager拿到文件夹下所有文件,传入path获取映射的文件,
        //  default为此文件路径
    const getUrl=(path)=>{
           const modules = import.meta.globEager('../../../assets/ft-images/*');
        return modules[path].default;
}