当前位置: 首页 > 文档资料 > uView 开发文档 >

AlertTips 警告提示

优质
小牛编辑
132浏览
2023-12-01

AlertTips 警告提示 使用场景
  • 当某个页面需要向用户显示警告的信息时。
  • 非浮层的静态展现形式,始终展现,不会自动消失,用户可以点击关闭。

平台差异说明

AppH5微信小程序支付宝小程序百度小程序头条小程序QQ小程序

基本使用

  • 通过titledescription设置组件的标题和描述内容,如果内容和标题同时存在,标题字体会被加粗加大
  • 通过type设置主题类型,有primary,success,error,warning,info可选值
<template>
	<u-alert-tips type="warning" :title="title" :description="description"></u-alert-tips>
</template>

<script>
	export default {
		data() {
			title: '登高望远',
			description: '欲穷千里目,更上一层楼'
		}
	}
</script>

图标

通过show-icon设置是否显示图标,作用是让信息类型更加醒目。

注意:当前版本图标为uView内置图标,根据type参数显示不同的图标,无法自定义。

<u-alert-tips type="warning" :show-icon="true"></u-alert-tips>

可关闭的警告提示

显示关闭按钮,点击可关闭警告提示。

  • close-text参数配置关闭的文字,默认为一个叉的icon图标。close-abletrue时有效
  • close-able参数配置是否允许关闭的文字或图标

注意

由于props传参的限制,您需要监听组件的close事件,并在此此事件中设置show参数为false,才能关闭组件。

<template>
	<u-alert-tips :show="show" type="error" @close="show = false" :title="title" :close-able="true"></u-alert-tips>
	
	<u-alert-tips type="error" :title="title" close-text="close" :description="description" :close-able="true"></u-alert-tips>
</template>

<script>
	export default {
		data() {
			title: '寻隐者不遇',
			description: '松下问童子,言师采药去。只在此山中,云深不知处。',
			show: true
		}
	}
</script>

API

Props

参数说明类型默认值可选值
title显示的文字String--
description辅助性文字,颜色比title浅一点,字号也小一点,可选String--
close-able关闭按钮(默认为叉号icon图标)Booleanfalsetrue
type使用预设的颜色Stringwarningsuccess / primary / error / info
close-text用文字替代关闭图标,close-abletrue时有效String--
show-icon是否显示左边的辅助图标Booleanfalsetrue
show显示或隐藏组件Booleantruefalse
icon 1.5.8左侧的图标名称,如设置typeshow-icon值,会有一个默认的图标String--
icon-style 1.5.8自定义图标的样式,对象形式Object--
title-style 1.5.8自定义标题的样式,对象形式Object--
desc-style 1.5.8自定义内容的样式,对象形式Object--

Events

事件名说明回调参数
close点击关闭按钮时触发,需在此回调设置showfalse-
click点击组件时触发-