Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<template>
<div :class="classes" role="alert" ref="alert">
{{ text }}
<button
v-if="dismissible"
type="button"
class="btn-close"
data-bs-dismiss="alert"
aria-label="Close"
></button>
</div>
</template>
<script>
export default {
props: { modelValue: { type: Object, default: () => {} } },
mounted: function() {
if (this.$refs.alert) {
this.$refs.alert.addEventListener("closed.bs.alert", this.disable);
}
},
methods: {
disable: function() {
this.$emit("update:modelValue", null);
console.log("click");
},
},
computed: {
classes: function() {
let classes = "alert alert-" + this.variant + " fade show";
if (this.dismissible) {
classes += " alert-dismissible";
}
return classes;
},
text: function() {
if (this.modelValue && typeof this.modelValue === "string") {
return this.modelValue;
} else {
if (this.modelValue && "text" in this.modelValue) {
return this.modelValue.text;
} else {
return "Illegal notification message structure";
}
}
},
variant: function() {
if (
this.modelValue &&
typeof this.modelValue === "object" &&
"variant" in this.modelValue
) {
return this.modelValue.variant;
} else {
return "info";
}
},
dismissible: function() {
if (
this.modelValue &&
typeof this.modelValue === "object" &&
"dismissible" in this.modelValue
) {
return this.modelValue.dismissible;
} else {
return false;
}
},
},
};
</script>
<style></style>