typescript封装JS的Callback
- JS原型 - plus.nativeUI.prompt("请输入内容",function(e){ - return e.index == 0 ? e.value : ""; });
- 改写成TS服务
Prompt(msg: string): Promise<string> {
        return new Promise<string>(
            (string) => {
                plus.nativeUI.prompt(msg, (e: any) => string (
                    e.index == 0 ? e.value : ""
                ));
            });
    }
- 调用 - plus.Prompt("请输入").then((s: string)=>(alert(s))); 
应该还有更好的方法,学习中...
评论已关闭