简体   繁体   English

使用VueJs2和Webpack的小册子CSS导入问题

[英]leaflet CSS import issue using VueJs2 and webpack

I'm trying to make a single file component using vuejs2 to display a Leaflet map. 我正在尝试使用vuejs2来显示一个Leaflet映射的单个文件组件。

Although my map component is mounted correctly I'm struggling with leaflet css import. 尽管我的地图组件已正确安装,但我仍在尝试使用传单CSS导入。 The tiles of the map appear all messy and I'm guessing that no style is applied on map block: Unordered tiles . 地图的图块看起来都很杂乱,我猜测地图块上没有应用任何样式: 无序图块 Neither webpack nor the browser console are displaying error. Webpack和浏览器控制台均未显示错误。

Any clue to load style sheets the proper way? 有什么线索可以正确加载样式表吗?

sources are available at github repo 源码可以在github repo上找到

There are at least two issues: 至少有两个问题:

  1. In webpack.config.js, you have options: {modules: true} enabled for CSS files. 在webpack.config.js中,您具有以下options: {modules: true}为CSS文件启用了options: {modules: true} This causes webpack to pre-process your leaflet.css file and mangle all selector names. 这将导致webpack预处理您的leaflet.css文件并更改所有选择器名称。 Change modules option to false 将模块选项更改为false

  2. Your map container needs to have an explicit size. 您的地图容器必须具有明确的大小。 For instance in the <style> section of your map-component.vue , add this: 例如,在map-component.vue<style>部分中,添加以下内容:

    .map-container { width: 800px; .map-container {width:800px; height: 600px; 高度:600像素; } }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM