Notify 消息提示
函数调用
Notify 是一个函数,调用后会直接在页面中弹出相应的消息提示。
组件调用
通过组件调用 Notify 时,可以通过下面的方式进行注册(从 2.8.5 版本开始支持):
import { Notify } from 'vant';
// 全局注册
Vue.use(Notify);
// 局部注册
export default {
components: {
[Notify.Component.name]: Notify.Component,
},
};
通知类型
// 主要通知
Notify({ type: 'primary', message: '通知内容' });
// 成功通知
Notify({ type: 'success', message: '通知内容' });
Notify({ type: 'danger', message: '通知内容' });
// 警告通知
Notify({ type: 'warning', message: '通知内容' });
自定义通知
自定义消息通知的颜色和展示时长。
引入 Notify 组件后,会自动在 Vue 的 prototype 上挂载 $notify
方法,便于在组件内调用。
export default {
this.$notify('提示文案');
},
};
组件调用
export default {
data() {
return {
show: false,
};
},
methods: {
showNotify() {
this.show = true;
setTimeout(() => {
this.show = false;
}, 2000);
},
};
API
方法
样式变量
组件提供了下列 Less 变量,可用于自定义样式,使用方法请参考主题定制。