vue build之后 无法访问element ui图标

前后端分离 项目部署 有两种方式
第一种是将build之后的dist文件夹放在springboot应用的static文件夹下 使用tomcat启动
第二种是使用nginx启动
而放在springboot应用中 使用tomcat启动 会出现无法访问element图标、字体的错误

方法一

使用maven资源过滤配置 这种方式适合于资源被过滤的情况

   <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <nonFilteredFileExtensions>
                        <nonFilteredFileExtension>woff</nonFilteredFileExtension>
                        <nonFilteredFileExtension>woff2</nonFilteredFileExtension>
                        <nonFilteredFileExtension>eot</nonFilteredFileExtension>
                        <nonFilteredFileExtension>ttf</nonFilteredFileExtension>
                        <nonFilteredFileExtension>svg</nonFilteredFileExtension>
                    </nonFilteredFileExtensions>
                </configuration>
            </plugin>
        </plugins>
    </build>

方法二

这种方法适合于资源访问链接错误导致的资源加载异常

*{pointer-events:none}
@font-face{font-family:element-icons;
src:url(/static/fonts/element-icons.535877f.woff)
format("woff"),url(/static/fonts/element-icons.732389d.ttf) 
format("truetype");font-weight:400;

CSS文件夹下的app.xxx.css文件中 找到static/fonts/element-icons.535877f.woff 在它的前面添加/dist/资源定位 这样就可以正常访问到图标文件了 顺便将static/fonts/element-icons.732389d.ttf也添加/dist/资源定位就可以了

方法三

直接在vue打包之前 配置好打包路径 也可以解决资源找不到的问题

  if (options.extract) {
      return ExtractTextPlugin.extract({
        use: loaders,
        fallback: 'vue-style-loader',
        
添加这一句代码
        publicPath:'../../'

      })
    } else {
      return ['vue-style-loader'].concat(loaders)
    }


打包后的文件 在对字体进行引用时 自动添加../..的资源定位

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值