下面是我的舊代碼的一個例子。此代碼創建了一個確認螢屏,并在確認后洗掉了一個用戶。但是我想使用 toast 元素來幫助創建更好的確認螢屏。此 toast 元素需要將方法拆分為 onConfirm 和 onReject。我想知道是否有一種方法可以將變數從我的 deleteUser 方法傳遞到 onConfirm 方法,類似于我在下面的代碼中傳遞它的方式。( .then(this.onTeacherDeleted(user))
deleteUser(user) {
if (confirm("Are you sure you want to delete: " user.name "?")) {
this.working = true;
axios.delete('/teachers/' user.id)
.then(this.onTeacherDeleted(user))}
// this.$toast.add({severity: 'warn', summary: 'Are you sure?', detail: 'Are you sure you want to delete this placement?', group: 'bc'});
},
onTeacherDeleted (user) {
this.$toast.add({severity:'success', summary: user.name 'Deleted Successfully', detail:'The teacher was successfully delted from the database', life: 3000});
window.location.reload()
}
如何將用戶變數從 deleteUser 方法傳遞到 onConfirm 方法?
deleteUser(user) {
this.$toast.add({severity: 'warn', summary: 'Are you sure?', detail: 'Are you sure you want to delete this placement?', group: 'bc'});
},
onConfirm(user) {
this.$toast.removeGroup('bc');
this.working = true;
axios.delete('/teachers/' user.id)
.then(this.onTeacherDeleted(user))
},
onReject() {
this.$toast.removeGroup('bc');
},
onConfirm 和 onReject 都是在代碼中較早發生的點擊事件(見下文):
<button class="btn border border-success rounded-3" type="button" @click="onConfirm" this.onTeacherDeleted(user) aria-expanded="false">
<button class="btn border border-danger rounded-3" type="button" @click="onReject" aria-expanded="false">
uj5u.com熱心網友回復:
如果您顯示更多代碼,也許我可以提供更好的解決方案,但據我所知,您可以創建一個變數來跟蹤當前正在洗掉的用戶并將其值設定為:
deleteUser(user) {
this.$toast.add({severity: 'warn', summary: 'Are you sure?', detail: 'Are you sure you want to delete this placement?', group: 'bc'});
this.userToBeDeleted = user;
},
然后在 onConfirm 中使用該變數:
onConfirm() {
this.$toast.removeGroup('bc');
this.working = true;
axios.delete('/teachers/' this.userToBeDeleted.id)
.then(this.onTeacherDeleted(this.userToBeDeleted))
},
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/536627.html
標籤:javascriptvue.js变量方法laravel-mix-vue3
下一篇:具有相同后綴的變數相乘相加
