fetch('./mock/data.json') 为什么请求public下的数据路径是./呢
来源:4-10 异步Action(1)

china092188
2019-11-19
fetch(’./mock/data.json’) 为什么请求public下的数据路径是./呢
fetch('./mock/data.json').then(
resolve=>{
resolve.json().then(data=>{
dispatch(fetchDataSuccess(data))
})
},
error=>{
dispatch(fetchDataFailure(error))
}
)
}
写回答
1回答
-
艾特老干部
2019-11-21
create-react-app会把public文件夹下的资源作为静态资源使用,这里./是相对路径的写法,是相对public文件夹而言。可以再看下2-2这一节。
10
相似问题