確認ダイアログを実装するなら「vuejs-dialog」がおすすめ! ループ時
by kabanoki
HTML
<div id="app">
<table>
<thead>
<th>No</th>
<th>name</th>
<th></th>
</thead>
<tbody>
<tr v-for="user in users">
<td>{{user.no}}</td>
<td>{{user.name}}</td>
<td>
<button v-confirm="onAlert(user)">確認</button>
</td>
</tr>
</tbody>
</table>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuejs-dialog.min.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuejs-dialog.min.js"></script>
<!--カスタムコンポーネントが必要な場合読みこむ -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuejs-dialog-mixin.min.js"></script>
CSS
#app {
background: #fff;
border-radius: 4px;
padding: 20px;
transition: all 0.2s;
}
button.open {
float:left;
height: 30px;
width: 12%;
margin: 3px;
background-color: #62caaa;
padding: 1px;
display: flex;
justify-content: center;
align-items: center;
color: #fff;
border: 2px solid #fff;
font-size: 18px;
border-radius: 10px;
}
table th {
font-weight: bold;
}
table th, table td {
padding: 10px;
border: 1px solid #dcdcdc;
}
Vue
const VuejsDialog = window.VuejsDialog.main.default;
Vue.use(VuejsDialog);
new Vue({
el: '#app',
data: {
users: [
{no:1, name:'太郎'},
{no:2, name:'二郎'},
{no:3, name:'花子'},
{no:4, name:'由香里'}
]
},
methods: {
makeAdmin:function(dialog, user){
// 成功時
setTimeout(function() {
dialog.close();
}, 1500);
},
doNothing:function(){
// 失敗時
},
onAlert:function(user){
let self = this;
return {
loader: true,
html: true,
ok: function(dialog){self.makeAdmin(dialog, user)},
cancel: this.doNothing(),
message: {
title: 'ユーザー確認',
body: 'あなたが選択したユーザーはこちら?<br><br><strong>No:</strong> '+ user.no +'<br><strong>ユーザー名:</strong> ' + user.name
}
};
}
}
});