Skip to content

Notify 消息提示

该组件一般用于页面顶部向下滑出一个提示,尔后自动收起的场景。

平台差异说明

App(vue)App(nvue)H5小程序

基本使用

html
<template>
	<up-notify message="Hi uview-ultra" :show="show"></up-notify>
</template>
js
<script setup>  
import { ref } from 'vue';  
  
// 创建响应式数据  
const show = ref(true);  
</script>
js
<script>
export default {
    data() {
        return {
            show: true
        }
    }
}
</script>

ref调用

html
<template>
	<up-notify ref="uNotifyRef" message="Hi uview-ultra"></up-notify>
</template>
js
<script setup>  
import { onMounted, ref, onUnmounted } from 'vue';  
  
// 假设你有一个 uNotify 组件的引用  
const uNotifyRef = ref(null);  
  
// 在组件挂载后执行  
onMounted(() => {  
    uNotifyRef.value.show({  
        top: 10,  
        type: 'error',  
        color: '#000',  
        bgColor: '#e8e8e8',  
        message: 'Hi uview-ultra',  
        duration: 1000 * 3,  
        fontSize: 20,  
        safeAreaInsetTop: true  
    });  
  
    // 你也可以定义其他方法或逻辑  
    // uNotifyRef.value.primary('Primary主题')
});  
  
// 如果需要,在组件卸载时关闭 notify  
onUnmounted(() => {  
    if (uNotifyRef.value) {  
        uNotifyRef.value.close();  
    }  
});  
</script>
js
<script>
export default {
    onReady(){
	    this.$refs.uNotify.show({
            top: 10,
            type: 'error',
            color: '#000',
            bgColor: '#e8e8e8',
            message: 'Hi uview-ultra',
            duration: 1000 * 3,
            fontSize: 20,
            safeAreaInsetTop:true
        })

        // 也可以通过主题形式调用,如:
        // this.$refs.uNotifyRef.primary('Primary主题')
        
        // 关闭 notify
        // this.$refs.uNotifyRef.close()
    }
}
</script>

右侧演示页面源代码地址

点击以下链接以查看右侧演示页面的源码


 github  gitee

API

Methods

事件名说明类型
show显示并加载配置Handler
primary / success / warning /error显示当前主题消息提示Handler
close关闭消息提示Handler

Show Methods Arguments

参数说明类型默认值可选值
top到顶部的距离String | Number0-
type主题,primary,success,warning,errorStringprimary-
color字体颜色String#ffffff-
bgColor背景颜色String--
message展示的文字内容String--
duration展示时长,为0时不消失,单位msString | Number3000-
fontSize字体大小,单位rpxString | Number15-
safeAreaInsetTop是否留出顶部安全距离(状态栏高度)Booleanfalsetrue

Slot

参数说明
icon通知内容