无法在指定时间后自动关闭 Vue-strap

Unable to auto close Vue-strap after specified duration

我在 Vue.js 中使用 Vue-strap 警报组件。警报框工作正常,但是,我无法在指定的持续时间后自动关闭警报框。这是我正在使用的组件代码。

 <alert :show.sync="showAlert" placement="top" duration="3000" type="success" width="400px" dismissable>
      <span class="icon-info-circled alert-icon-float-left"></span>
      <strong>Success</strong>
      <p>{{alertMessage}}</p> 
    </alert>

单击关闭 (x) 按钮时,警告框保持打开和关闭状态。下面是一个使用了alert组件的码笔。
https://codepen.io/Taxali/pen/dKJpKY

任何建议,如何在 3 秒后自动关闭警告框?谢谢。

根据 source code,setTimeout(_, duration) 仅在 show props 发生变化时设置。 所以有一个解决方法,您可以在 mounted 方法中将 showfalse 切换到 true,或者您可以使用按钮来切换警报。

在 Vue 组件中 setTimeout 自己的另一种方式。

 var vm = new Vue({
    components: {
        alert:VueStrap.alert,
    },
    el: "#app",
    data: {
        alertMessage:"Activity Saved Successfully.",
        showAlert:false
    },
    mounted() {
      this.showAlert = true
    }
})
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue-strap/1.1.40/vue-strap.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">

<div id="app">
  
  <alert :show.sync="showAlert" placement="top" :duration="3000" type="success" width="400px" dismissable >
   <span class="icon-info-circled alert-icon-float-left"></span>
   <strong>Success</strong>
   <p>{{alertMessage}}</p> 
 </alert>
  
</div>