J
J
jekanok2021-02-25 19:10:02
Vue.js
jekanok, 2021-02-25 19:10:02

How to open local files in vue?

Hello, the question is how to open the xml file in the xml/rss.xml folder via fetch if I have a folder structure6037cb77964e7222512538.png

await fetch("./xml/rss.xml")
      .then((response) => response.text())
      .then((data) => {
        const parser = new DOMParser();
        const xml = parser.parseFromString(data, "application/xml");
        console.log(xml);
      })
      .catch(console.error);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin B., 2021-02-25
@jekanok

What you are doing is in a different context
. You need to move the xml folder to public, and remove . to get "/xml/rss.xml"
Thus, your file will be loaded on the client and processed there.
If you want to do this when building, then look towards require

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question