[英]JQuery-mobile. Can't open the dialog programmatically; tried everything I could think of
[英]Can't open Vuetify dialog programmatically in setTimeout callback
默認情況下, Vuetify
對話框的顯示由切換dialog
布爾變量值的按鈕控制。
我假設以編程方式更改此變量的值將允許顯示或隱藏對話框,但事實並非如此。 為什么不?
這是我的代碼:
<template>
<div>
<v-dialog v-model="dialog">
<v-card>
Dialog content
</v-card>
</v-dialog>
</div>
</template>
<script>
export default {
data() {
return {
dialog: false
}
},
mounted() {
console.log(this.dialog);
setTimeout(function() {
this.dialog = true;
console.log(this.dialog);
}, 2000);
}
}
</script>
控制台顯示false
頁面加載,那么true
2秒后。 但是對話框仍然沒有出現......
您應該使用箭頭函數()=>
作為setTimeout
回調:
mounted() {
console.log(this.dialog);
setTimeout(()=> {
this.dialog = true;
console.log(this.dialog);
}, 2000);
}
請參閱 boussadjra ( @boussadjra ) 在CodePen上的 Pen Vuetify Dialog 示例。
您在調用 setTimeout 函數內的變量時遇到了一些麻煩。
嘗試這個:
<template>
<div>
<v-dialog v-model="dialog">
<v-card>
Dialog content
</v-card>
</v-dialog>
</div>
</template>
<script>
export default {
data() {
return {
dialog: false
}
},
mounted() {
that = this
console.log(this.dialog);
setTimeout(function() {
that.dialog = true;
console.log(that.dialog);
}, 2000);
}
}
</script>
嘗試從相關問題中閱讀此答案,並在匿名函數中調用它
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.