gpt4 book ai didi

reactjs - axios未定义

转载 作者:行者123 更新时间:2023-12-03 13:12:56 26 4
gpt4 key购买 nike

我正在使用 axios 通过 React.js 构建一个简单的天气应用程序。我刚刚完成了代码,但是有一个问题。当我启动该应用程序时,它根本无法工作,并且我看到一个引用错误,指出 axios is not Defined

这是我的 webpack.config.js 文件:

module.exports = {
entry: './public/app/app.jsx',
output: {
path: __dirname,
filename: './public/js/bundle.js'
},
externals: ['axios'],
resolve: {
root: __dirname,
alias: {
OpenWeatherMap: 'public/components/OpenWeatherMap.jsx',
Main: 'public/components/Main.jsx',
Nav: 'public/components/Nav.jsx',
Weather: 'public/components/Weather.jsx',
WeatherForm: 'public/components/WeatherForm.jsx',
WeatherMessage: 'public/components/WeatherMessage.jsx',
About: 'public/components/About.jsx'
},
extensions: ['', '.js', '.jsx']
},
module: {
loaders: [{
loader: 'babel-loader',
query: {
presets: ['react','es2015', 'stage-0']
},
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/
},{
loader: 'json-loader',
test: /\.json?$/
}]
}
};

和 package.json 文件:

{
"name": "weather",
"version": "1.0.0",
"description": "Simple Weather App",
"main": "ext.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Milad Fattahi",
"license": "ISC",
"dependencies": {
"axios": "^0.16.1",
"express": "^4.15.3",
"json": "^9.0.6",
"json-loader": "^0.5.4",
"react": "^15.5.4",
"react-dom": "^15.5.4",
"react-router": "^4.1.1",
"react-router-dom": "^4.1.1"
},
"devDependencies": {
"babel-core": "^6.5.1",
"babel-loader": "^6.2.2",
"babel-preset-es2015": "^6.5.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.24.1",
"webpack": "^1.12.13"
}
}

最佳答案

我知道这可能看起来很明显,但请确保文件顶部有对正确 axios 的引用或安装它 https://www.npmjs.com/package/axios

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>

关于reactjs - axios未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44342142/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com