Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

239
Views
cuando uso la palabra async en webpack-3, la función no funciona

Estaba usando async: false en ajax. Quiero tener el equivalente de este comando en fetch. Aparentemente, usar async ayuda. Pero cuando uso la palabra asíncrono en el paquete web, no funciona. uso webbpack 3.8.1 y en 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'] } } }, ] } };

en mi archivo:

 async function f12() { alert('13579-1122'); } f12();

No funciona cuando uso la palabra asíncrono. (Quiero que el programa espere a que se complete el comando de búsqueda cuando se está ejecutando el comando de búsqueda. Estaba usando async: false en ajax)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Tenga una función que solo fetches los datos y llame a esa función desde una función asíncrona que awaits la respuesta (JSON, presumiblemente), la analiza y luego puede hacer lo que quiera con ella.

Un poco como esto:

 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();

Documentación adicional

  • async/await

  • fetch

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!