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...

javascript 复制代码
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 的替代方案

方案一:

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

或页面中直接使用

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

方案二:

js 复制代码
// 方案解析:通过import.meta.globEager拿到文件夹下所有文件,传入path获取映射的文件,
        //  default为此文件路径
    const getUrl=(path)=>{
           const modules = import.meta.globEager('../../../assets/ft-images/*');
        return modules[path].default;
}
相关推荐
Predestination王瀞潞9 分钟前
5.4.3 通信->WWW万维网内容访问标准(W3C):WWW(World Wide Web) 协议架构(分层)
前端·网络·网络协议·架构·www
爱学习的程序媛19 分钟前
【Web前端】优化Core Web Vitals提升用户体验
前端·ui·web·ux·用户体验
zabr20 分钟前
花了 100+ 篇笔记,我整理出 了一套 AI Agent 工程完全指南
前端·后端·agent
软弹32 分钟前
深入理解 React Ref 机制:useRef 与 forwardRef 的协作原理
前端·javascript·react.js
YaHuiLiang36 分钟前
Ai Coding浪潮下的前端:“AI在左,裁员在右”
前端
雪碧聊技术44 分钟前
前端vue代码架子搭建
前端·javascript·vue.js·前端项目代码框架搭建
爱学习的程序媛44 分钟前
【Web前端】前端用户体验优化全攻略
前端·ui·交互·web·ux·用户体验
han_1 小时前
JavaScript设计模式(二):策略模式实现与应用
前端·javascript·设计模式
x***r1511 小时前
Notepad++ 8.6 安装教程:详细步骤+自定义安装路径(附注意事项)
linux·前端·javascript
Hilaku1 小时前
为什么很多工作 5 年的前端,身价反而卡住了?🤷‍♂️
前端·javascript·面试