简体   繁体   English

如何将传单折线装饰器与 vue 应用程序一起使用

[英]How can I use leaflet-polylinedecorator with a vue app

I have a Vue 2 sample project at https://github.com/ericg-vue-questions/leaflet-test我在https://github.com/ericg-vue-questions/leaflet-test有一个 Vue 2 示例项目

This is a simple import issue for my code that I am not sure how to handle.这是我的代码的一个简单导入问题,我不确定如何处理。

A couple of things I have tried are to modify the code to do:我尝试过的几件事是修改代码

<script>
import "leaflet/dist/leaflet.css";
import L from "leaflet";
import * from 'leaflet-polylinedecorator';

but this results in a build error:但这会导致构建错误:

  10:9  error  Parsing error: Unexpected token, expected "as"
> 4 | import * from 'leaflet-polylinedecorator';

To the index.html , I also tried adding:对于index.html ,我还尝试添加:

<script src="../node_modules/leaflet-polylinedecorator/dist/leaflet.polylineDecorator.js"></script>

but that results in the runtime error:但这会导致运行时错误:

Uncaught SyntaxError: Unexpected token '<' (at leaflet.polylineDecorator.js:1:1)

What needs to be changed so I can import and use this leaflet extension with a vue app?需要更改什么,以便我可以导入此 leaflet 扩展并将其与 vue 应用程序一起使用?

A solution I found was to modify main.js so it looks like:我发现的一个解决方案是修改main.js ,使它看起来像:

import Vue from 'vue'
import App from './App.vue'

Vue.config.productionTip = false

require( "../node_modules/leaflet-polylinedecorator/dist/leaflet.polylineDecorator.js" );

new Vue({
  render: h => h(App),
}).$mount('#app')

Adding the require resolved the problem.添加require解决了这个问题。

I would be interested in alternative solutions, if there are any.如果有的话,我会对替代解决方案感兴趣。

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

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