Notice-Notification通知

亦凉 2022-03-22 04:10 421阅读 0赞
  1. <div id="app">
  2. <el-button
  3. plain
  4. @click="open">
  5. 可自动关闭
  6. </el-button>
  7. <el-button
  8. plain
  9. @click="open2">
  10. 不会自动关闭
  11. </el-button>
  12. </div>
  13. <script>
  14. /*
  15. * Notification 组件提供通知功能,Element 注册了$notify方法,接收一个options字面量参数,在最简单的情况下,你可以设置
  16. title字段和message字段,用于设置通知的标题和正文。
  17. * 默认情况下,经过一段时间后 Notification 组件会自动关闭,但是通过设置duration,可以控制关闭的时间间隔,特别的是,如果
  18. 设置为0,则不会自动关闭。注意:duration接收一个Number,单位为毫秒,默认为4500。
  19. * */
  20. new Vue({
  21. el: '#app',
  22. methods: {
  23. open() {
  24. const h = this.$createElement;
  25. console.log(h)
  26. this.$notify({
  27. title: '标题名称',
  28. message: h('i', { style: 'color: teal'}, '这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案')
  29. });
  30. },
  31. open2() {
  32. this.$notify({
  33. title: '提示',
  34. message: '这是一条不会自动关闭的消息',
  35. duration: 0
  36. });
  37. }
  38. }
  39. })
  40. </script>

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2hyYnNmZHh6aHEwMQ_size_16_color_FFFFFF_t_70

  1. <script>
  2. /*
  3. * NElement 为 Notification 组件准备了四种通知类型:success, warning, info, error。通过type字段来设置,除此以外的值将被忽略。同时,
  4. * 我们也为 Notification 的各种 type 注册了方法,可以在不传入type字段的情况下像open5和open6那样直接调用。
  5. * */
  6. new Vue({
  7. el: '#app',
  8. methods: {
  9. open3() {
  10. this.$notify({
  11. title: '成功',
  12. message: '这是一条成功的提示消息',
  13. type: 'success'
  14. });
  15. },
  16. open4() {
  17. this.$notify({
  18. title: '警告',
  19. message: '这是一条警告的提示消息',
  20. type: 'warning'
  21. });
  22. },
  23. open5() {
  24. this.$notify.info({
  25. title: '消息',
  26. message: '这是一条消息的提示消息'
  27. });
  28. },
  29. open6() {
  30. this.$notify.error({
  31. title: '错误',
  32. message: '这是一条错误的提示消息'
  33. });
  34. }
  35. }
  36. })
  37. </script>

全局方法

Element 为 Vue.prototype 添加了全局方法 $notify。因此在 vue instance 中可以采用本页面中的方式调用 Notification。

Options









































参数 说明 类型 可选值 默认值
title 标题 string
message 说明文字 string/Vue.VNode
type 主题样式,如果不在可选值内将被忽略 string success/warning/info/error
duration 显示时间, 毫秒。设为 0 则不会自动关闭 number 4500

发表评论

表情:
评论列表 (有 0 条评论,421人围观)

还没有评论,来说两句吧...

相关阅读