无法在Vue中编译GeoJson文件

时间:2018-09-27 05:53:33

标签: vue.js webpack


我是vue js的新手,我想制作一个gis app,我使用webpack+vue和一个geojson文件作为底图。不幸的是,当我尝试编译它时,出现了错误消息:
Module parse failed: Unexpected token (2:6) You may need an appropriate loader to handle this file type.
这是我的代码:

export default {
    data: function () {
      return {
        map: null,
        bounds: null,
        zona: require('@/assets/data/zona.geojson'),
        zonaLayer: null,
      }
    },
    mounted: function () {
      this.bounds = new google.maps.LatLngBounds();
      const mapCentre = this.markerCoordinates[0]
      const options = {
        center: new google.maps.LatLng(mapCentre.latitude, mapCentre.longitude),
        mapTypeControl: false,
        scaleControl: false,
        scrollwheel: false,
        navigationControl: false
      }
      this.map = new google.maps.Map(element, options);
      this.zonaLayer = new google.maps.Data({map: this.map})
      this.zonaLayer.loadGeoJson(this.zona);
    }   };

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

我在https://github.com/soal/vue-mapbox/issues/104找到了答案:

// webpack.conf.js
...
resolve: {
    extensions: ['.js', '.vue', '.json'],
    alias: {
      'vue$': 'vue/dist/vue.esm.js',
      '@': resolve('src'),
      'vue-mapbox': path.resolve(__dirname, '../node_modules/vue-mapbox/dist/vue-mapbox.umd.min.js'),
    }
  },
...

我仍在他们的快速入门中,但这对我有用。