Toast in Vant sets the global delay time operation

  • 2021-09-12 00:05:39
  • OfStack

In the configuration file that introduced Toast, the configuration is as follows:


import { Toast } from 'vant';
Vue.use(Toast);
Toast.setDefaultOptions({ duration: 800 });  // duration Delay time 

-End.

Supplementary knowledge: vant ui library toast use and encapsulation

Recently, I am writing a project, and there are many form items, so it is necessary to do verification at the front end. It is too cumbersome to write one by one, so I can package it and call it directly:

1. Create toast. js


import { Toast } from 'vant'
import 'vant/lib/index.css'

export function toast(message, duration = 1000) {
  Toast({
    message, duration
  });
 }

2. Use the

import { toast } from'../assets/js/toast'

toast ('prompt information ');


Related articles: