Решено - Vue JS Маркеры Google Map из файла JSON. Неожиданный токен} в JSON в позиции 139 - PullRequest
1 голос
/ 20 марта 2020

Я использую Vue JS и пытаюсь создать маркеры для карты Google из файла JSON. Это полное сообщение об ошибке: «Сбой сборки модуля: SyntaxError: Неожиданный токен» в JSON в позиции 139 в JSON .parse () в Object.module.exports (E: \ just \ path \ project \ node_modules \ json -loader \ index. js: 4: 49) "В нем говорится, что проблема в индексе. js в позиции 4:49, но я не знаю, что должно быть не так. Я никогда не редактировал этот файл.

Вот часть сценария карты файлов. vue:

    <script>

import { stanice } from '../json/data.json'

export default{
  name: "Map",
  data () {
    return {
      center: { lat: 50.425, lng: 14.907 },
      infoContent: '',
      infoWindowPos: null,
      infoWinOpen: false,
      currentMidx: null,
      infoOptions: {
          pixelOffset: {
          width: 0,
          height: -35
          }
        },
     };
  },
  computed: {
    markers() {
      return stanice.map(({ location: { lat, lng }, name }) => ({
        position: {
          lat,
          lng
        },
        name
      }));
    }
  },
  methods: {
    getPosition: function(marker) {
      return {
        lat: parseFloat(marker.position.lat),
        lng: parseFloat(marker.position.lng)
      }
    },
    toggleInfoWindow: function(marker, index) {
      this.infoWindowPos = this.getPosition(marker);
      this.infoContent = marker.text;

      if (this.currentMidx == index) {
        this.infoWinOpen = !this.infoWinOpen;
      }
      else{
        this.infoWinOpen = true;
        this.currentMidx = index;
      }
    }
  }
};

</script>

Это данные. json file:

{
  "stanice": [
    {
      "name": "Meteostanice 1",
      "location": {
        "lat": 50.43,
        "lng": 14.91
      }
    },
    {
      "name": "Meteostanice 2",
      "location": {
        "lat": 50.43,
        "lng": 14.915
      }
    },
    {
      "name": "Meteostanice 3",
      "location": {
        "lat": 50.43,
        "lng": 14.92
      }
    }
  ]
}

И это тот индексный файл. js, расположенный в папке json -loader:

module.exports = function (source) {
  if (this.cacheable) this.cacheable();

  var value = typeof source === "string" ? JSON.parse(source) : source;

  value = JSON.stringify(value)
    .replace(/\u2028/g, '\\u2028')
    .replace(/\u2029/g, '\\u2029');

  return `module.exports = ${value}`;
}

Некоторые вещи на моем родном языке, поэтому я надеюсь, что это не проблема;)

Спасибо всем за помощь!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...