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;
}
相关推荐
布瑞泽的童话15 分钟前
Vue 也能这样玩?Vuetify 打造超强大的UI体验
前端·vue.js·ui·开源
加勒比海涛17 分钟前
ElementUI 快速入门:使用 Vue 脚手架搭建项目
前端·vue.js·elementui
安冬的码畜日常24 分钟前
【CSS in Depth 2 精译_031】5.3 Grid 网格布局的两种替代语法
前端·css·css3·html5·网格布局·网格·css布局
sun_weitao25 分钟前
extends in javascript
开发语言·前端·javascript
Jiaberrr1 小时前
轻松切换淘宝最新镜像源,加速npm依赖安装
前端·javascript·vue.js·npm·node.js
Teln_小凯1 小时前
VUE + NODE 历史版本安装
前端·javascript·vue.js
hai405871 小时前
切换淘宝最新npm镜像源是
前端·npm·node.js
亦世凡华、1 小时前
探索 Electron:助力文档操作应用快速落地
前端·javascript·经验分享·electron·前端框架
waterHBO1 小时前
react js 使用 useEffect 钩子
前端·javascript·react.js
aimmon1 小时前
Superset二次开发之源码DependencyList.tsx 分析
前端·typescript·二次开发·bi·superset