据我所知,有两种选择promise:
好的,我知道是什么promise.all().它并行运行promises,.then如果两者成功解析,则为您提供值.这是一个例子:
Promise.all([
$.ajax({ url: 'test1.php' }),
$.ajax({ url: 'test2.php' })
])
.then(([res1, res2]) => {
// Both requests resolved
})
.catch(error => {
// Something went wrong
});
Run Code Online (Sandbox Code Playgroud)
但我不明白promise.race()应该做什么呢?换句话说,不使用它有什么区别?假设这个:
$.ajax({
url: 'test1.php',
async: true,
success: function (data) {
// This request resolved
}
});
$.ajax({
url: 'test2.php',
async: true,
success: function (data) {
// This request resolved
}
});
Run Code Online (Sandbox Code Playgroud)
看到?我没有使用promise.race()它,它表现得像promise.race().无论如何,有什么简单而干净的例子可以告诉我何时应该使用promise.race()?
mPdf - niklasravnsborg/laravel-pdf我正在尝试使用laravel 5.5生成 pdf 。但每次我以纵向模式获取 pdf 时。
public function showCertificate()
{
$data = [ 'name' => 'John Doe', 'prize' => '1st Prize'];
$pdf = PDF::loadView('certificates.show',
$data,
[],
[
'title' => 'Certificate',
'orientation' => 'L'
]);
return $pdf->stream('certificate.pdf');
}
Run Code Online (Sandbox Code Playgroud)