Javascript Axios未编译
我已经用npm安装了axios,但由于某些原因,它无法编译 my package.json文件的一个片段:Javascript Axios未编译,javascript,reactjs,axios,Javascript,Reactjs,Axios,我已经用npm安装了axios,但由于某些原因,它无法编译 my package.json文件的一个片段: "aws4": { "version": "1.9.1", "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.9.1.tgz", "integrity": "s
"aws4": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/aws4/-/aws4-1.9.1.tgz",
"integrity": "sha512-wMHVg2EOHaMRxbzgFJ9gtjOOCrI80OHLG14rxi28XwOW8ux6IiEbRCGGGqCtdAIg4FQCbW20k9RsT4y3gJlFug=="
},
"axios": {
"version": "0.19.2",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz",
"integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==",
"requires": {
"follow-redirects": "1.5.10"
},
"dependencies": {
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"axios": "^0.19.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.1"
},
my package.lock.json文件的一个片段:
"aws4": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/aws4/-/aws4-1.9.1.tgz",
"integrity": "sha512-wMHVg2EOHaMRxbzgFJ9gtjOOCrI80OHLG14rxi28XwOW8ux6IiEbRCGGGqCtdAIg4FQCbW20k9RsT4y3gJlFug=="
},
"axios": {
"version": "0.19.2",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz",
"integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==",
"requires": {
"follow-redirects": "1.5.10"
},
"dependencies": {
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"axios": "^0.19.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.1"
},
我使用axios的地方:
import React, {useState} from 'react';
import Search from './components/search.js';
import axios from 'axois';
function App() {
const [state, setState] = useState({
s: "", //search query. empty string is default entry
results: [], //initially, no results, so empty array
selected: {}, //the actual element clicked up out of the presented results
})
const apiurl = "http://www.omdbapi.com/?i=tt3896198&apikey=af1c6093";
const search = (e) => {
if(e.key === "Enter") {
axios(apiurl + "&s=" + state.s).then((data) => {
console.log(data);
});
}
}
提前感谢您的帮助!如果您希望我提供更多的上下文/代码,请告诉我
更新:
-我修复了写“Axis”而不是“axios”的尴尬错误,但我目前有一个新问题-元素类型无效,请检查应用程序的渲染方法。我在这个网站上找到了另一篇文章,目前正在尝试解决这个问题。也许是进出口问题?尽管如此,谢谢你的帮助 您的导入有一个输入错误。axios应该是axios。使用
import axios from 'axios';
而不是
import axios from 'axois';
从“Axis”导入axios;那应该是“axios”而不是“axios”