我在ajax中使用了异步: false。我希望在fetch中使用与此命令相当的命令。显然使用异步有帮助。但是当我在webpack中使用异步这个词时,它就不起作用了。我使用webbpack 3.8.1,在webpack.config.js中:
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const extractCSS = new ExtractTextPlugin('allstyles_for_store_details_naghashi.css'/*'allstyles_for_store_details.css'*//*'allstyles.css'*/);
module.exports = {
entry: {
'main': './wwwroot/source/app_for_store_details_naghashi.js' ,
},
output: {
path: path.resolve(__dirname, 'wwwroot/dist'),
filename: 'bundle_for_store_details_naghashi.js' ,
publicPath: 'dist/',
},
plugins: [
extractCSS,
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
Popper: ['popper.js', 'default']
}),
new webpack.optimize.UglifyJsPlugin(),
],
module: {
rules: [
{
test: /\.css$/, use: extractCSS.extract(['css-loader?minimize'])
},
{
test: /\.js?$/,
use: {
loader: 'babel-loader', options: {
presets:
['@babel/preset-react', '@babel/preset-env']
}
}
},
]
}
};在我的档案里:
async function f12() {
alert('13579-1122');
}
f12(); 当我使用异步这个词时,它不起作用。(我希望程序在fetch命令运行时等待fetch命令完成。我在ajax中使用了异步: false )
发布于 2022-02-13 11:58:16
有一个函数只需对数据进行fetches,并从异步函数调用该函数,即awaits响应(想必是JSON),解析它,然后您可以使用它做任何事。
有点像这样:
function getData(url) {
return fetch(url);
}
async function main() {
try {
const response = await getData('https://example.com');
const data = await response.json();
console.log(data);
} catch(err) {
console.log(err);
}
}
main();
补充文件
https://stackoverflow.com/questions/71100201
复制相似问题