在vue+cli项目中使用iview组件及icon图标,打包后icon不显示,解决办法:
1.在build文件夹下找到utils.js文件,把publicPath改为 ../../

if (options.extract) {  
  return ExtractTextPlugin.extract({  
    publicPath:'../../',  
    use: loaders,  
    fallback: 'vue-style-loader'  
  })  
} else {  
  return ['vue-style-loader'].concat(loaders)  
}

2.在build文件夹下找到webpack.prod.conf.js文件,修改extract为 false

module: {  
  rules: utils.styleLoaders({  
  sourceMap: config.build.productionSourceMap,  
  extract: false,  
  usePostCSS: true  
  })  
},

如果上面两种方案都没有解决的话,找到iview.css文件查看iview.css中引入font图标的地址是否正确

@font-face {  
  font-family: Ionicons;  
  src: url(../font/ionicons.eot?v=2.0.0);  
  src: url(../font/ionicons.eot?v=2.0.0#iefix) format("embedded-opentype"), url(../font/ionicons.ttf?v=2.0.0) format("truetype"), url(../font/ionicons.woff?v=2.0.0) format("woff"), url(../font/ionicons.svg?v=2.0.0#Ionicons) format("svg");  
  font-weight: 400;  
  font-style: normal  
}

瑞瑞_
73 声望8 粉丝