Как я могу использовать ax ios внутри файла html (pug)? - PullRequest
0 голосов
/ 24 апреля 2020

Я работаю над своим первым сайтом. Нужно иметь систему фильтров для продуктов. Я могу получить все данные, которые мне нужны, но не могу получить результат от ax ios. Сообщение об ошибке не дает мне большой подсказки относительно того, как это исправить. Он просто говорит: «Необработанное отклонение обещания: SyntaxError: Строка не соответствует ожидаемому шаблону». Кто-нибудь может помочь? Как я могу использовать ax ios в моем html файле или отправить данные параметров вне файла куда-нибудь, где я могу использовать ax ios.

  script(src='https://unpkg.com/axios/dist/axios.min.js')
  script(src='filter.js')
  script(type='text/javascript' src='script.js')
  script.
    function openNav() {
      document.getElementById("mySidenav").style.width = "275px";
    }

    function closeNav() {
      document.getElementById("mySidenav").style.width = "0";
    }

    async function applyFilter() {
      let temp = document.getElementById('flag_category');
      const category = temp.options[temp.selectedIndex].value;
      temp = document.getElementById('flag_color');
      const color = temp.options[temp.selectedIndex].value;
      temp = document.getElementById('flag_theme');
      const theme = temp.options[temp.selectedIndex].value;
      temp = document.getElementById('flag_flagType');
      const flagType = temp.options[temp.selectedIndex].value;
      temp = document.getElementById('flag_fabricType');
      const fabricType = temp.options[temp.selectedIndex].value;

      if (color !== '') color = `color: '${color}',\n`;
      if (theme !== '') theme = `theme: '${theme}',\n`;
      if (flagType !== '') flagType = `flagType: '${flagType}',\n`;
      if (fabricType !== '') fabricType = `fabricType: '${fabricType}',\n`;
      if (category !== '') category = `category: '${category}',\n`;

      params = color + theme + flagType + fabricType + category;

      const flags = axios({
        method: 'get',
        url: 'http://127.0.0.1:3000api/v1/flags',
        data: { params }
      });
      console.log(flags);
      /*
        res.status(200).render('flagOverview', {
          title: 'Flags',
          products: flags
        });
        */
    };

1 Ответ

2 голосов
/ 24 апреля 2020

Я думаю, проблема в этой строке:

url: 'http://127.0.0.1: 3000api / v1 / flags ',

It должно быть:

url: 'http://127.0.0.1: 3000 / api / v1 / flags ',

Вы пропустили sla sh .

...