点我扫二维码,查看demo

# Toast 轻提示

# 介绍

在页面中间弹出黑色半透明提示,用于消息通知、加载提示、操作结果提示等场景。

# 引入

通过以下方式来按需注册组件。

import Vue from 'vue';
import { Toast } from '@dolphin-iot/ui'

Vue.use(Toast);
1
2
3
4

# 代码演示

# 基础用法

通过show属性,判断当前是否展示提示框,message属性用于展示提示内容。

<div class="demo-list">
    <div class="panel">
        <mx-cell title="基础用法"  type="link"  @click="show = true" />
        <div class="demo-panel">
            <mx-toast :show="show" message="连接中" @close="show = !show" />
        </div>
    </div>
</div>
<script>
export default {
    data() {
        return {
            show: false
        }
    }
}
</script>
<style lang="scss" scoped>
.demo-list {
  .demo-panel {
    position: relative;
    padding-top: 20px;
    .temp {
      width: 40px;
      height: 40px;
      background: #f2f3f5;
      border-radius: 4px;
    }

    /deep/.mx-badge-wrapper {
      margin-left: 16px;
    }
  }
}
</style>
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

# 自定义主题

<div class="demo-list">
    <div class="panel">
        <mx-cell title="dark" type="link" @click="show = true" />
        <mx-cell title="light" type="link" @click="light = true" />
        <div class="demo-panel">
            <mx-toast :show="dark" theme="dark" message="连接中"  @close="dark = !dark" />
            <mx-toast :show="light" theme="light" message="连接中" @close="light = !light" />
        </div>
    </div>
</div>
<script>
export default {
    data() {
        return {
            dark: false,
            light: false
        }
    }
}
</script>
<style lang="scss" scoped>
.demo-list {
  .demo-panel {
    position: relative;
    padding-top: 20px;
    .temp {
      width: 40px;
      height: 40px;
      background: #f2f3f5;
      border-radius: 4px;
    }

    /deep/.mx-badge-wrapper {
      margin-left: 16px;
    }
  }
}
</style>

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

# 自定义位置

组件中的position属性用于判断提示框展示的位置,选项分别有 top center bottom

<div class="demo-list">
    <div class="panel">
        <mx-cell title="top" type="link" @click="top = true" />
        <mx-cell title="center" type="link" @click="center = true" />
        <mx-cell title="bottom" type="link" @click="bottom = true" />
        <div class="demo-panel">
            <mx-toast :show="top"  message="连接中" position="top"  @close="top = !top" />
            <mx-toast :show="center" message="连接中" position="center" @close="center = !center" />
            <mx-toast :show="bottom"  message="连接中" position="bottom"  @close="bottom = !bottom" />
        </div>
    </div>
</div>
<script>
export default {
    data() {
        return {
            top: false,
            center: false,
            bottom: false
        }
    }
}
</script>
<style lang="scss" scoped>
.demo-list {
  .demo-panel {
    position: relative;
    padding-top: 20px;
    .temp {
      width: 40px;
      height: 40px;
      background: #f2f3f5;
      border-radius: 4px;
    }
    /deep/.mx-badge-wrapper {
      margin-left: 16px;
    }
  }
}
</style>

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

# 显示加载中

根据loading属性,判断是否显示loading加载图标;一句overlay判断是否展示遮罩层。

<div class="demo-list">
    <div class="panel">
        <mx-cell title="loading" type="link" @click="loading = true" />
        <div class="demo-panel">
            <mx-toast :show="loading" theme="light" overlay :loading="true" message="加载中" position="center"  @close="loading = !loading" />
        </div>
    </div>
</div>
<script>
export default {
    data() {
        return {
            loading: false
        }
    }
}
</script>
<style lang="scss" scoped>
.demo-list {
  .demo-panel {
    position: relative;
    padding-top: 20px;
    .temp {
      width: 40px;
      height: 40px;
      background: #f2f3f5;
      border-radius: 4px;
    }

    /deep/.mx-badge-wrapper {
      margin-left: 16px;
    }
  }
}
</style>
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

# 自定义图标

通过icon属性自定义提示框中的图标。

<div class="demo-list">
    <div class="panel">
        <mx-cell title="自定义图标" type="link" @click="icon = true" />
        <div class="demo-panel">
            <mx-toast :show="icon" icon="star" theme="light" message="自定义图标" position="center"  @close="icon = !icon" />
        </div>
    </div>
</div>
<script>
export default {
    data() {
        return {
            icon: false
        }
    }
}
</script>
<style lang="scss" scoped>
.demo-list {
  .demo-panel {
    position: relative;
    padding-top: 20px;
    .temp {
      width: 40px;
      height: 40px;
      background: #f2f3f5;
      border-radius: 4px;
    }

    /deep/.mx-badge-wrapper {
      margin-left: 16px;
    }
  }
}
</style>

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

# 函数式调用(v0.2.0版本开始支持)

函数调用支持的参数与组件的方式支持的 props 是一致的。

<template>
  <div>
    <h4>函数调用</h4>
    <mx-cell title="函数调用" type="link" @click="onShowToast" />
  </div>
</template>
<script>
export default {
  methods:{
    onShowToast(){
      this.$toast({
        icon:'star',
        theme:'light',
        message:'函数调用',
        position:'center'
      })
    }
  }
}
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

# Api

# Props

参数 说明 类型 默认值 是否必须
show 是否显示提示 boolean false -
overlay 是否显示遮罩层 boolean false -
theme 提示主题色,可选值为:light dark string dark -
zIndex 弹出层在z轴的序号 number 1030 -
message 自定义提示消息 string - -
duration 提示展示事件,单位:ms number 1600 -
overlay-style 提示自定义样式 object - -
position 提示展示位置,可选值为: top bottom center string bottom -
close-on-click-overaly 是否在点击遮罩层后关闭 boolean true -
icon 提示框中自定义图标 string - -
loading 是否显示加载 boolean false -

# Events

名称 说明 回调参数
close 关闭时触发 e: boolean
更新时间: 4/7/2022, 9:23:32 AM