import Vue from 'vue';
import { Notify } from 'vant';
Vue.use(Notify);
Notify('Notify Message');
Notify({ type: 'primary', message: 'Notify Message' });
Notify({ type: 'success', message: 'Notify Message' });
Notify({ type: 'danger', message: 'Notify Message' });
Notify({ type: 'warning', message: 'Notify Message' });
Notify({
message: 'Custom Color',
color: '#ad0000',
background: '#ffe1e1',
});
Notify({
message: 'Custom Duration',
duration: 1000,
});
After import the Notify component, the $notify method is automatically mounted on Vue.prototype, making it easy to call within a vue component.
export default {
mounted() {
this.$notify('Notify Message');
},
};
<van-button type="primary" text="Component Call" @click="showNotify" />
<van-notify v-model="show" type="success">
<van-icon name="bell" style="margin-right: 4px;" />
<span>Content</span>
</van-notify>
export default {
data() {
return {
show: false,
};
},
methods: {
showNotify() {
this.show = true;
setTimeout(() => {
this.show = false;
}, 2000);
},
},
};
| Methods |
Attribute |
Return value |
Description |
| Notify |
`options |
message` |
notify instance |
| Notify.clear |
- |
void |
Close notify |
| Notify.setDefaultOptions |
options |
void |
Set default options of all notifies |
| Notify.resetDefaultOptions |
- |
void |
Reset default options of all notifies |
| Attribute |
Description |
Type |
Default |
type v2.1.6 |
Can be set to primary success warning |
string |
danger |
| message |
Message |
string |
- |
| duration |
Duration(ms), won't disappear if value is 0 |
number | string |
3000 |
| color |
Message color |
string |
white |
| background |
Background color |
string |
- |
| className |
Custom className |
any |
- |
| onClick |
Callback function after click |
Function |
- |
| onOpened |
Callback function after opened |
Function |
- |
| onClose |
Callback function after close |
Function |
- |