アプリみたいに通知数を表示できるライブラリ「vue-notification-bell」
by kabanoki
HTML
<link rel="stylesheet" href="https://unpkg.com/bootstrap/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/NotificationBell.umd.min.js"></script>
<div id="app">
<notification-bell
:size="100"
:count="list.length"
upper-limit="50"
counter-location="upperRight"
counter-style="roundRectangle"
counter-background-color="#FF0000"
counter-text-color="#FFFFFF"
icon-color="#000000"
font-size="25px"
:animated="true"
></notification-bell>
<ul class="list-group">
<li class="list-group-item" v-for="(item, index) in list" :key="index">{{'item-'+item.no}} - <button class="btn btn-danger" type="button" @click="deleteItem(index)">削除する</button></li>
</ul>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.min.js"></script>
CSS
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
#app {
background: #fff;
border-radius: 4px;
padding: 20px;
transition: all 0.2s;
}
li {
margin: 8px 0;
}
h2 {
font-weight: bold;
margin-bottom: 15px;
}
del {
color: rgba(0, 0, 0, 0.3);
}
Vue
const NotificationBell = window['NotificationBell'].default;
new Vue({
el: '#app',
components: {
'notification-bell':NotificationBell
},
data: {
list: [
{no:1},
{no:2},
{no:3},
{no:4},
{no:5},
]
},
methods: {
deleteItem: function(index){
this.list.splice(index, 1);
}
}
});