Vue.js - 解决部署到服务器后Element UI图标不显示问题(404错误)

1,问题描述
(1)element-ui 自带了一套常用的图标集合,使用起来十分方便。最近发现当 Vue.js 项目中使用 element-ui 图标时,如果使用 npm run dev 方式启动,图标是显示正常的:
(2)而一旦使用 npm run build 编译打包后发布到服务器上,会发现图片显示不出来(Chrome 浏览器下显示方块)。
原文:Vue.js - 解决部署到服务器后Element UI图标不显示问题(404错误)

(3)查看网络请求可以看到如下两个字体文件加载不到:
http://localhost:59090/static/css/static/fonts/element-icons.535877f.woff
http://localhost:59090/static/css/static/fonts/element-icons.732389d.ttf
原文:Vue.js - 解决部署到服务器后Element UI图标不显示问题(404错误)

2,问题原因
(1)查看 /build/webpack.base.conf.js 文件可以发现,woff 或 ttf 这些字体会经由 url-loader 处理后在 static/fonts 目录下生成相应的文件。
原文:Vue.js - 解决部署到服务器后Element UI图标不显示问题(404错误)

(2)也就是说实际应该通过 /static/fonts/** 路径来获取字体图标,而实际却是请求 /static/css/static/fonts/**,自然报 404 错误。
原文:Vue.js - 解决部署到服务器后Element UI图标不显示问题(404错误)

3,解决办法
(1)打开 build/utils.js 文件,在如下位置添加 publicPath: ‘…/…/’
原文:Vue.js - 解决部署到服务器后Element UI图标不显示问题(404错误)
在这里插入图片描述
(2)修改完毕后重新 build 发布,可以发现图标已经可以正常显示了。
原文:Vue.js - 解决部署到服务器后Element UI图标不显示问题(404错误)

原文出自:www.hangge.com 转载请保留原文链接:https://www.hangge.com/blog/cache/detail_2473.html

  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
可以使用 Vue-cli 快速搭建基于 Vue.js 的项目结构并在此基础上添加 element-ui 和 three.js 的依赖库。以下是相关的命令: 1. 安装 Vue-cli ``` npm install -g @vue/cli ``` 2. 创建一个基于 Vue.js 的项目 ``` vue create your-project-name ``` 3. 进入项目目录并添加 element-ui 和 three.js 的依赖库 ``` cd your-project-name npm i element-ui three ``` 4. 在 main.js 中导入 element-ui 和 three.js 的样式和组件 ```javascript import Vue from 'vue' import ElementUI from 'element-ui' import 'element-ui/lib/theme-chalk/index.css' import * as THREE from 'three' import App from './App.vue' Vue.config.productionTip = false Vue.use(ElementUI) Vue.prototype.$THREE = THREE new Vue({ render: h => h(App), }).$mount('#app') ``` 5. 在 App.vue 中创建一个包含 three.js 场景的组件 ```vue <template> <div class="three-container"></div> </template> <script> export default { name: 'App', mounted () { // 初始化 three.js 场景 const scene = new this.$THREE.Scene() const camera = new this.$THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 ) const renderer = new this.$THREE.WebGLRenderer() renderer.setSize(window.innerWidth, window.innerHeight) document.querySelector('.three-container').appendChild(renderer.domElement) const geometry = new this.$THREE.BoxGeometry(1, 1, 1) const material = new this.$THREE.MeshBasicMaterial({ color: 0x00ff00 }) const cube = new this.$THREE.Mesh(geometry, material) scene.add(cube) camera.position.z = 5 const animate = () => { requestAnimationFrame(animate) cube.rotation.x += 0.01 cube.rotation.y += 0.01 renderer.render(scene, camera) } animate() } } </script> <style scoped> .three-container { width: 100%; height: 100%; position: fixed; } </style> ``` 这样就可以创建一个基于 Vue.jselement-ui 和 three.js 的后台管理系统模板。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值