在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ 用Vue構(gòu)建一個彈窗組件如何實現(xiàn)隊列機制和自動銷毀

用Vue構(gòu)建一個彈窗組件如何實現(xiàn)隊列機制和自動銷毀

  1. 如何動態(tài)創(chuàng)建這個組件?(例如AJAX后調(diào)用組件顯示信息)
  2. 如何自動銷毀?(例如創(chuàng)建成功后一定時間自動銷毀或隱藏)
  3. 如何將同時創(chuàng)建的多個組件隊列化?(在上一個組件消失后緊接著顯示下一個)

       <div id="atn">
           <todo-item
             v-for="(item,index) in msg_list"
             v-bind:todo="item"
             v-bind:key="item.index"
             v-show="item.show">
           </todo-item>
       </div>
       <script>
           // 構(gòu)建
       Vue.component('todo-item', {
         props: ['todo'],
         template: '<div class="atn-msg">@{{ todo.text }}</div>'
       })
       // 實例化
       var app = new Vue({
         el: '#atn',
         data: {
           msg_list: [
             {text: '提示信息1',show:true },
             {text: '提示信息2',show:false },
           ]
         }
       })
       </script>
       
       <style>
       .atn-msg{
           position: fixed;
           z-index: 1000;
           bottom: 20vh;
           left: 50%;
           display: flex;
           justify-content: center;
           align-items: center;
           padding: .5rem 1rem;
           border-radius: 20rem;
           background: rgba(0,0,0,0.5);
           color: #fff;
           animation-duration: .4s;
           animation-fill-mode: forwards;
           animation-name: fadeIn;
       }
       </style>
回答
編輯回答
久舊酒

可以看看iview的message組件源碼。

分為兩部分:

1、管理對象。保存彈窗隊列,有創(chuàng)建、銷毀方法,你要實現(xiàn)的邏輯都在這個管理對象里面。

2、彈窗組件是一個無狀態(tài)組件。單純做內(nèi)容展示。

2018年3月17日 09:03