Home > front end >  React in a fetch an error, please everyone a great god guide
React in a fetch an error, please everyone a great god guide

Time:09-22

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

CodePudding user response:

The fetch MDN link: https://developer.mozilla.org/zh-CN/docs/Web/API/Fetch_API

CodePudding user response:

Bosses, I see you send the link, but did not solve my problem

CodePudding user response:

You try to import the test from './test. The md '; The sentence below. Add a console log (test), and then enter the page to see the console,,,

CodePudding user response:

I doubt that is the time to build, webpack judgment test has not been used, so this resource has not been packaged to come in, but why is there the fetch (test); A reference is thus not clear; Could you as the upstairs said, write a sentence: the console. The log (test); , keep the reference to the test, let webpack identification to the test resources are in use
  • Related