纷享销客开发者手册 纷享销客开发者手册
  • APL开发手册
  • PWC开发手册
  • OpenAPI 文档
  • 自定义组件(PC端)
  • 自定义组件(小程序)
  • 自定义插件(PC端)
  • 自定义插件(小程序)
  • 第三方集成插件(H5)
  • API(PC端)
  • API(小程序)
  • Fx DevTools
更新日志
  • 简体中文
  • English
  • 自定义组件(PC端)
  • 自定义组件(小程序)
  • 自定义插件(PC端)
  • 自定义插件(小程序)
  • 第三方集成插件(H5)
  • API(PC端)
  • API(小程序)
  • Fx DevTools
更新日志
  • 简体中文
  • English
  • 入门

  • 组件

    • 组件总览
    • UI组件

      • 按钮
      • 单选框
      • 多选框
      • 输入框
      • 计数器
      • 选择器
      • 级联选择器
      • 开关
      • 时间选择器
      • 日期选择器
      • 日期时间选择器
      • 上传
      • 颜色选择器
      • 表格
      • 标签
      • 进度条
      • 树形控件
      • 分页
      • 标记
      • 警告
      • 消息提示
        • 弹框
        • 通知
        • 下拉菜单
        • 步骤条
        • 对话框
        • 卡片
        • 日历
        • 文字提示
        • 弹出框
        • 折叠面板
        • 走马灯
      • 业务组件

    • 示例

    • 常见问题

    目录

    消息提示

    # Message 消息提示

    常用于主动操作后的反馈提示。与 Notification 的区别是后者更多用于系统级通知的被动提醒。

    # 基础用法

    从顶部出现,3 秒后自动消失。

    打开消息提示 VNode

    Message 在配置上与 Notification 非常类似,所以部分 options 在此不做详尽解释,文末有 options 列表,可以结合 Notification 的文档理解它们。FxUI 注册了一个$message方法用于调用,Message 可以接收一个字符串或一个 VNode 作为参数,它会被显示为正文内容。

    <template>
      <fx-button :plain="true" @click="open">打开消息提示</fx-button>
      <fx-button :plain="true" @click="openVn">VNode</fx-button>
    </template>
    
    <script>
      export default {
        methods: {
          open() {
            this.$message('这是一条消息提示');
            
            // this.$message({
            //   isMiddler:1,
            //   iconClass:'no',
            //   duration:100000,
            //   message:'这是一条消息提示'
            // });
          },
    
          openVn() {
            const h = this.$createElement;
            this.$message({
              message: h('p', null, [
                h('span', null, '内容可以是 '),
                h('i', { style: 'color: teal' }, 'VNode')
              ])
            });
          }
        }
      }
    </script>
    
    显示代码 复制代码 复制代码

    # 不同状态

    用来显示「成功、警告、消息、错误」类的操作反馈。

    成功 警告 消息 错误

    当需要自定义更多属性时,Message 也可以接收一个对象为参数。比如,设置type字段可以定义不同的状态,默认为info。此时正文内容以message的值传入。同时,我们也为 Message 的各种 type 注册了方法,可以在不传入type字段的情况下像open4那样直接调用。

    <template>
      <fx-button :plain="true" @click="open2">成功</fx-button>
      <fx-button :plain="true" @click="open3">警告</fx-button>
      <fx-button :plain="true" @click="open1">消息</fx-button>
      <fx-button :plain="true" @click="open4">错误</fx-button>
    </template>
    
    <script>
      export default {
        methods: {
          open1() {
            this.$message('这是一条消息提示');
          },
          open2() {
            this.$message({
              message: '恭喜您,这是一条成功消息',
              type: 'success'
            });
          },
    
          open3() {
            this.$message({
              message: '警告哦,这是一条警告消息',
              type: 'warning'
            });
          },
    
          open4() {
            this.$message.error('错了哦,这是一条错误消息');
          }
        }
      }
    </script>
    
    显示代码 复制代码 复制代码

    # 可关闭

    可以添加关闭按钮。

    消息 成功 警告 错误

    默认的 Message 是不可以被人工关闭的,如果需要可手动关闭的 Message,可以使用showClose字段。此外,和 Notification 一样,Message 拥有可控的duration,设置0为不会被自动关闭,默认为 3000 毫秒。

    <template>
      <fx-button :plain="true" @click="open1">消息</fx-button>
      <fx-button :plain="true" @click="open2">成功</fx-button>
      <fx-button :plain="true" @click="open3">警告</fx-button>
      <fx-button :plain="true" @click="open4">错误</fx-button>
    </template>
    
    <script>
      export default {
        methods: {
          open1() {
            this.$message({
              showClose: true,
              message: '这是一条消息提示'
            });
          },
    
          open2() {
            this.$message({
              showClose: true,
              message: '恭喜您,这是一条成功消息',
              type: 'success'
            });
          },
    
          open3() {
            this.$message({
              showClose: true,
              message: '警告哦,这是一条警告消息',
              type: 'warning'
            });
          },
    
          open4() {
            this.$message({
              showClose: true,
              message: '错了哦,这是一条错误消息',
              type: 'error'
            });
          }
        }
      }
    </script>
    
    显示代码 复制代码 复制代码

    # 文字居中

    使用 center 属性让文字水平居中。

    文字居中
    <template>
      <fx-button :plain="true" @click="openCenter">文字居中</fx-button>
    </template>
    
    <script>
      export default {
        methods: {
          openCenter() {
            this.$message({
              message: '居中的文字',
              center: true
            });
          }
        }
      }
    </script>
    
    显示代码 复制代码 复制代码

    # 使用 HTML 片段

    message 属性支持传入 HTML 片段

    使用 HTML 片段

    将dangerouslyUseHTMLString属性设置为 true,message 就会被当作 HTML 片段处理。

    <template>
      <fx-button :plain="true" @click="openHTML">使用 HTML 片段</fx-button>
    </template>
    
    <script>
      export default {
        methods: {
          openHTML() {
            this.$message({
              dangerouslyUseHTMLString: true,
              message: '<strong>这是 <i>HTML</i> 片段</strong>'
            });
          }
        }
      }
    </script>
    
    显示代码 复制代码 复制代码

    :::warning message 属性虽然支持传入 HTML 片段,但是在网站上动态渲染任意 HTML 是非常危险的,因为容易导致 XSS 攻击 (opens new window)。因此在 dangerouslyUseHTMLString 打开的情况下,请确保 message 的内容是可信的,永远不要将用户提交的内容赋值给 message 属性。 :::

    # 全局方法

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

    # 单独引用

    单独引入 Message:

    import { Message } from 'fx-ui';
    

    此时调用方法为 Message(options)。我们也为每个 type 定义了各自的方法,如 Message.success(options)。并且可以调用 Message.closeAll() 手动关闭所有实例。

    # Options

    参数 说明 类型 可选值 默认值 PC/移动端支持情况
    message 消息文字 string / VNode — — PC/移动端不支持VNode
    type 主题 string success/warning/info/error info PC/移动端仅支持text/loading/ success
    iconClass 自定义图标的类名,会覆盖 type string — — PC/移动端
    dangerouslyUseHTMLString 是否将 message 属性作为 HTML 片段处理 boolean — false 仅PC
    customClass 自定义类名 string — — PC/移动端
    duration 显示时间, 毫秒。设为 0 则不会自动关闭 number — 3000 PC/移动端
    showClose 是否显示关闭按钮 boolean — false 仅PC
    center 文字是否居中 boolean — false PC/移动端
    position 文字位置 String top/middle/bottom middle 仅移动端
    isMiddler 提示框是否垂直居中 boolean — - 仅PC
    onClose 关闭时的回调函数, 参数为被关闭的 message 实例 function — — 仅PC
    offset Message 距离窗口顶部的偏移量 number — 20 仅PC

    # 方法

    调用 Message 或 this.$message 会返回当前 Message 的实例。如果需要手动关闭实例,可以调用它的 close 方法。

    方法名 说明
    close 关闭当前的 Message
    警告
    弹框

    ← 警告 弹框→

    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式