MsgKit.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <template>
  2. <v-snackbar top v-model="visible" :color="color" :timeout="timeout">
  3. <v-icon left>{{ icon }}</v-icon> {{ msg }}
  4. <template v-slot:action="{ attr }">
  5. <v-btn text v-bind="attr" @click="visible = false">关 闭</v-btn>
  6. </template>
  7. </v-snackbar>
  8. </template>
  9. <script>
  10. export default {
  11. name: 'MsgKit',
  12. data: () => ({
  13. visible: false,
  14. msg: 'Hello, Friends!',
  15. color: 'teal',
  16. timeout: 2000,
  17. icon: 'mdi-check-circle-outline'
  18. }),
  19. methods: {
  20. normal (msg, color = '#2196F3', timeout = 2000, icon = 'mdi-information-outline') {
  21. this.visible = true
  22. this.msg = msg
  23. this.color = color
  24. this.timeout = timeout
  25. this.icon = icon
  26. },
  27. success (msg, timeout = 2000) {
  28. this.normal(msg, '#009688', timeout, 'mdi-check-circle-outline')
  29. },
  30. warning (msg, timeout = 2000) {
  31. this.normal(msg, '#673AB7', timeout, 'mdi-alert-octagram-outline')
  32. },
  33. error (msg, timeout = 2000) {
  34. this.normal(msg, '#C62828', timeout, 'mdi-sticker-remove-outline')
  35. }
  36. }
  37. }
  38. </script>