Home > front end >  React in a local file content error, please call the younger brother what some directions
React in a local file content error, please call the younger brother what some directions

Time:11-29

React, fetch way to obtain a local file, and will read it into a string, once after the start, there is no problem, but the NPM run after the build, the browser console shows the fetch method error, namely the fetch apis always load file:///... , I know the fetch error reason is need to preach a url, but do not know how to spread here, please god to give me some directions, the younger brother grateful, of course, I'm here to explain why I use this fetch, as follows:

Import the test from './test. The md ';

ComponentDidMount=()=& gt; {
Fetch (test)//is at fault here
Then (res=& gt; Res. The text ())
Then (text=& gt; {
.
});
}

Is because I want to get to the content of the markdown files, and then parse, so I only found on the Internet such a method can obtain the file content, and read into string format, the great god have what way can read text content as a string, or me how to use the fetch that can once run build after normal use
  • Related