首页 > 其他分享 >js-promise

js-promise

时间:2023-10-05 14:55:48浏览次数:26  
标签:function console log js promise reject

一 基本使用

<script  >
    let func = function mineReadFile(path){
// 注意这里必须是箭头函数。规范要这样写。 return new Promise((resolve, reject) => { if(path == "1"){ resolve("333"); }else{ reject("444") } }); } function test(){ console.log("----")
// 传的参数是两个函数 func("1").then((data)=>{ console.log(data); }, err=>{ console.log(err) }); } </script>

 

标签:function,console,log,js,promise,reject
From: https://www.cnblogs.com/Insist-Y/p/17743322.html

相关文章

  • MongoDBHelper + Expression+ JsonResult
    usingMongoDB.Driver;usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Linq.Expressions;namespaceMongodbTest.Common{///<summary>///MongoDb帮助类///</summary>publicclassMongoDbHelper......
  • vue-router.esm.js:2065 Uncaught (in promise) Error: Redirected when going from "
    原因:  vue-router路由版本更新产生的问题,导致路由跳转失败抛出该错误;真正的原因是由于返回了一个Promise对象,正常的跳转由then方法执行当正常的路由跳转,被"路由导航守卫"拦截并重新指定路由时,由于this.$router.push()返回的是Promise对象,此时then方法不能正常执......
  • 使用html和js写一个音乐播放器
    代码如下<!DOCTYPEhtml><html><head><metacharset="utf-8"><title>音乐播放器</title><style>@font-face{font-family:'ChillCalligraphy';......
  • [Compose] Asynchronous Reactive Data with Promises
    Let’smakeusingtheobserversasynchronous!Thiswaywecanupdatethedataandhavemultipleobserversrunasynchronously.classAsyncData{constructor(initialData){this.data=initialData;this.subscribers=[];}//Subscribetochan......
  • json.dump()的用法
    一、JSON是什么JSON是用于存储和交换数据的语法。JSON(JavaScriptObjectNotation)最初是用JavaScript对象表示法编写的文本,但随后成为了一种常见格式,被包括Python在内的众多语言采用。python里面的语言对象一般只有python能读懂,为了能比较好储存,而且能够让别的编程语言也能......
  • 鸿蒙JS UI的Hml语法技巧,hml中实现多列表的方式
    由于没有web基础,不懂html和js。需要从基础学起。刚刚学到在hml中实现多列表的方式,记录一下<divclass="container"><divclass="card-container"for="iteminimageCards"show="{{item.isShow}}"><divclass="text-container&......
  • Module build failed (from ./node_modules/css-loader/dist/cjs.js): CssSyntaxError
    问题描述在webpack的时候报错ERRORin./packages/theme-chalk/mixins/mixins.scss(./node_modules/css-loader/dist/cjs.js!./packages/theme-chalk/mixins/mixins.scss)Modulebuildfailed(from./node_modules/css-loader/dist/cjs.js):CssSyntaxError(14:8)......
  • Angular 应用构建完成后 vendor.js 文件的使用场合
    vendor.js文件的来源、作用和使用场合vendor.js文件是Angular应用中的一个重要文件,它承担了许多关键任务,包括管理应用的依赖关系、提供框架核心功能以及优化构建。本文将详细介绍vendor.js的来源、作用和使用场合,并通过示例来阐述。来源vendor.js文件的来源可以追溯到Angular应......
  • Go - Creating JSON Data Streams from Structs
    Problem: YouwanttocreatestreamingJSONdatafromstructs.Solution: CreateanencoderusingNewEncoderintheencoding/jsonpackage,passingitanio.Writer.ThencallEncodeontheencodertoencodestructsdatatoastream. Theio.Writerinterfa......
  • Go - Creating JSON Data Byte Arrays from Structs
    Problem: YouwanttocreateJSONdatafromastruct.Solution: Createthestructsthenusethejson.Marshalorjson.MarshalIndenttomarshalthedataintoaJSONsliceofbytes. funcmain(){person:=struct{}data,err:=......