小编pat*_*pan的帖子

获取本地文件的请求不起作用

我正在尝试在本地文件中发出请求,但我不知道我何时尝试在计算机上显示错误.是否可以获取项目中的文件?

 // Option 1
 componentDidMount() {
     fetch('./movies.json')
     .then(res => res.json())
     .then((data) => {
        console.log(data)
     });
 }

 error: Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0 at App.js: 10 -->  .then(res => res.json())

 // Option 2
 componentDidMount() {
    fetch('./movies.json', {
       headers : { 
         'Content-Type': 'application/json',
         'Accept': 'application/json'
       }
    })
   .then( res => res.json())
   .then((data) => {
        console.log(data);
   });
 }

 error1: GET http://localhost:3000/movies.json 404 (Not Found) at App.js:15 --> fetch('./movies.json', {
 error2: Uncaught (in promise) SyntaxError: Unexpected token …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs fetch-api

14
推荐指数
5
解决办法
3万
查看次数

如何使用yarn安装git存储库的特定分支?

我可以安装一个GitHub包,但不能安装其他纱线.请告诉我这里可能出现的问题.

我可以添加https://github.com/fancyapps/fancybox#3.0 但不能添加https://github.com/opentripplanner/otp-react-redux#result-post-processor

ravis-MacBook-Pro:gitprojects raviramadoss$ mkdir test
ravis-MacBook-Pro:gitprojects raviramadoss$ cd test
ravis-MacBook-Pro:test raviramadoss$ yarn init
yarn init v1.6.0
question name (test): 
question version (1.0.0): 
question description: 
question entry point (index.js): 
question repository url: 
question author: 
question license (MIT): 
question private: 
success Saved package.json
?  Done in 11.54s.

ravis-MacBook-Pro:test raviramadoss$ yarn add https://github.com/fancyapps/fancybox#3.0
yarn add v1.6.0
info No lockfile found.
[1/4]   Resolving packages...
[2/4]   Fetching packages...
[3/4]   Linking dependencies...
warning " > @fancyapps/fancybox@3.0.48" has unmet peer dependency "jquery@>=1.9.0".
[4/4] …
Run Code Online (Sandbox Code Playgroud)

node.js yarnpkg

11
推荐指数
2
解决办法
8393
查看次数

标签 统计

fetch-api ×1

javascript ×1

node.js ×1

reactjs ×1

yarnpkg ×1