为了将全屏按钮添加到我的叶映射到nuxt中,我已经安装了leaflet.fullscreen包,并且我已经编辑了我的插件leaflet.js,如下所示:
import Vue from "vue";
import { LMap, LTileLayer, LMarker, LPolyline } from "vue2-leaflet";
require("leaflet-routing-machine");
require("lrm-graphhopper");
require("leaflet.fullscreen");所以我可以在我的主模板中使用它:
<template>
<div>
<section class="search__page">
<div id="map-wrap" class="map__wrapper"></div>
</section>
</div>
</template>
<script>
import Tmap from "@/utils/TripMap.js";
export default {
mounted() {
this.initTmap();
},
data() {
return {
mainMap: null,
},
methods: {
initTmap() {
this.mainMap = new Tmap();
this.mainMap.load();
}
}
}
</script>我的类看起来是这样的:
export default class Tmap {
constructor() {
this.map = null;
}
load) {
this.map = L.map("map-wrap", {
fullscreenControl: true,
fullscreenControlOptions: {
position: "topleft"
}).setView([46.7227062, 2.5046503], 6);
L.tileLayer("http://{s}.tile.osm.org/{z}/{x}/{y}.png", {
maxZoom: 18,
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>, ©TRIP'
}).addTo(this.map);
}
addMarkerOnClick() {
this.map.addEventListener("click", ev => {
L.marker(ev.latlng).addTo(this.map);
});
}
getBounds() {
return this.map.getBounds();
}
}所以在我的主组件中,我不知道如何导入与这个全屏插件相关的css。我试过了:
<style>
@import "~/node_modules/leaflet.fullscreen/Control.FullScreen.css";
</style>这是可行的,但这显然不是一个好方法。你知道该怎么做吗?
发布于 2020-01-17 19:38:45
根据快速的web研究,我会说你应该能够像这样访问样式:
@import "~leaflet/dist/leaflet.css";当你在nuxt.config.js中注册一个全局样式时,应用程序只会加载一次。我假设由于node_modules路径的原因,您的构建花费了比平时更多的时间。
// nuxt.config.js
css: ['~/assets/styles/global.css'],你也可以试一试nuxt resource loader。
https://stackoverflow.com/questions/59773210
复制相似问题