1 回答
TA贡献1111条经验 获得超0个赞
使用v-model而不是v-if. 这是一个延迟 2 秒的简单示例:
new Vue({
el: "#app",
data() {
return {
showAlert: false,
alertMessage: 'This is the alert message'
}
},
methods: {
delayedAlert() {
this.showAlert = true;
setTimeout(() => {
this.showAlert = false;
}, 2000);
}
}
});
<div id="app">
<button @click="delayedAlert">Show alert for 2s</button>
<b-alert v-model="showAlert">
{{alertMessage}}
</b-alert>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.3/js/bootstrap.min.js"></script>
<script src="https://unpkg.com/vue@2.6.12/dist/vue.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-vue/2.19.0/bootstrap-vue.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.3/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-vue/2.19.0/bootstrap-vue.min.css" rel="stylesheet" />
添加回答
举报