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;
}
相关推荐
Highcharts.js几秒前
用 Highcharts如何创建一个音频图表
javascript·信息可视化·音视频·highcharts·音频图表
全栈小51 分钟前
【前端】win11操作系统安装完最新版本的NodeJs运行npm install报错,提示在此系统上禁止运行脚本
前端·npm·node.js
晚霞的不甘5 分钟前
Flutter for OpenHarmony3D DNA 螺旋可视化:用 Canvas 构建沉浸式分子模型
前端·数据库·经验分享·flutter·3d·前端框架
摘星编程1 小时前
React Native + OpenHarmony:Stepper步进器组件
javascript·react native·react.js
●VON1 小时前
React Native for OpenHarmony:简易计算器应用的开发与跨平台适配实践
javascript·react native·react.js
摘星编程8 小时前
OpenHarmony + RN:Placeholder文本占位
javascript·react native·react.js
a1117769 小时前
医院挂号预约系统(开源 Fastapi+vue2)
前端·vue.js·python·html5·fastapi
0思必得09 小时前
[Web自动化] Selenium处理iframe和frame
前端·爬虫·python·selenium·自动化·web自动化
计算机毕设VX:Fegn08959 小时前
计算机毕业设计|基于springboot + vue蛋糕店管理系统(源码+数据库+文档)
数据库·vue.js·spring boot·后端·课程设计
行走的陀螺仪11 小时前
uni-app + Vue3编辑页/新增页面给列表页传参
前端·vue.js·uni-app