Refactor success and error notifications to prevent html in them
This commit is contained in:
parent
cdc805c8da
commit
0e53745e91
2 changed files with 22 additions and 20 deletions
|
@ -11,13 +11,17 @@
|
|||
>
|
||||
<div
|
||||
class="notification-title"
|
||||
v-html="props.item.title"
|
||||
v-if="props.item.title"
|
||||
></div>
|
||||
>
|
||||
{{ props.item.title }}
|
||||
</div>
|
||||
<div
|
||||
class="notification-content"
|
||||
v-html="props.item.text"
|
||||
></div>
|
||||
>
|
||||
<template v-for="(t, k) in props.item.text">
|
||||
{{ t }}<br :key="k"/>
|
||||
</template>
|
||||
</div>
|
||||
<div
|
||||
class="buttons is-right"
|
||||
v-if="
|
||||
|
|
|
@ -1,31 +1,29 @@
|
|||
const getText = t => {
|
||||
|
||||
if (t.response && t.response.data && t.response.data.message) {
|
||||
return [
|
||||
t.message,
|
||||
t.response.data.message
|
||||
]
|
||||
}
|
||||
|
||||
return [t.message]
|
||||
}
|
||||
|
||||
export default {
|
||||
error(e, context, actions = []) {
|
||||
// Build the notification text from error response
|
||||
let err = e.message
|
||||
if (e.response && e.response.data && e.response.data.message) {
|
||||
err += '<br/>' + e.response.data.message
|
||||
}
|
||||
|
||||
// Fire a notification
|
||||
context.$notify({
|
||||
type: 'error',
|
||||
title: 'Error',
|
||||
text: err,
|
||||
text: getText(e),
|
||||
actions: actions,
|
||||
})
|
||||
},
|
||||
success(e, context, actions = []) {
|
||||
// Build the notification text from error response
|
||||
let err = e.message
|
||||
if (e.response && e.response.data && e.response.data.message) {
|
||||
err += '<br/>' + e.response.data.message
|
||||
}
|
||||
|
||||
// Fire a notification
|
||||
context.$notify({
|
||||
type: 'success',
|
||||
title: 'Success',
|
||||
text: err,
|
||||
text: getText(e),
|
||||
data: {
|
||||
actions: actions,
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue