Async/await 在 NativeScript-vue 中。为什么对话框不会以正确的顺序显示_?
Async/await in NativeScript-vue. Why dialogs won't show in correct order_?
如何在 nativescript-vue 中使用 await sync?
下面的 Vue 代码在浏览器中以正确的顺序显示,但在 nativescript 中更改了对话框顺序。
有人能猜出这里出了什么问题吗?
工作 Vue 代码
async start() {
await this.speak("first");
this.answer = await this.ask("question");
await this.speak(this.answer);
},
相同的代码现在可以在使用 nativescript 时以正确的顺序显示对话框。
confirm() 方法总是首先显示。
var app = new Vue({
el: '#app',
data: {
message: "starting point",
answer: " "
},
methods: {
async start() {
await this.speak("first");
this.answer = await this.ask("question");
await this.speak(this.answer);
},
speak(incoming) {
this.message = incoming + " speech";
alert(incoming);
},
ask(incoming) {
this.answer = prompt(incoming);
this.message = this.answer + " was the answer ";
return this.answer;
}
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<h2>{{ message }}</h2>
<button @click="start">Start</button>
</div>
这是因为 Web 浏览器中的警告对话框阻止了主线程上的所有其他 JavaScript 代码 运行。另外 alert(...)
returns 在 Web 上无效。
在 NativeScript 中 alert(...)
returns 确保对话框关闭的承诺。当在 {N} 中执行相同的代码时,它不会等待 alert(...)
对话框关闭,因为您没有返回承诺。
speak(incoming) {
this.message = incoming + " speech";
return alert(incoming);
},
如何在 nativescript-vue 中使用 await sync? 下面的 Vue 代码在浏览器中以正确的顺序显示,但在 nativescript 中更改了对话框顺序。 有人能猜出这里出了什么问题吗?
工作 Vue 代码
async start() {
await this.speak("first");
this.answer = await this.ask("question");
await this.speak(this.answer);
},
相同的代码现在可以在使用 nativescript 时以正确的顺序显示对话框。 confirm() 方法总是首先显示。
var app = new Vue({
el: '#app',
data: {
message: "starting point",
answer: " "
},
methods: {
async start() {
await this.speak("first");
this.answer = await this.ask("question");
await this.speak(this.answer);
},
speak(incoming) {
this.message = incoming + " speech";
alert(incoming);
},
ask(incoming) {
this.answer = prompt(incoming);
this.message = this.answer + " was the answer ";
return this.answer;
}
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<h2>{{ message }}</h2>
<button @click="start">Start</button>
</div>
这是因为 Web 浏览器中的警告对话框阻止了主线程上的所有其他 JavaScript 代码 运行。另外 alert(...)
returns 在 Web 上无效。
在 NativeScript 中 alert(...)
returns 确保对话框关闭的承诺。当在 {N} 中执行相同的代码时,它不会等待 alert(...)
对话框关闭,因为您没有返回承诺。
speak(incoming) {
this.message = incoming + " speech";
return alert(incoming);
},