[英]set toastr options globally using javascript
我有一组全部使用Toastr的脚本。 他们看起来像这样:
import $ from 'jquery';
import toastr from 'toastr';
import list from './data/address';
import { selectedApp, validate, getCookie, setCookie } from './common';
$(document).ready(function () {
toastr.options = {
'closeButton': true,
'debug': true,
'newestOnTop': false,
'progressBar': true,
'positionClass': 'toast-top-full-width',
'preventDuplicates': false,
'onclick': null,
'showDuration': '6000',
'hideDuration': '1000',
'timeOut': '50000',
'extendedTimeOut': '1000',
'showEasing': 'swing',
'hideEasing': 'linear',
'showMethod': 'fadeIn',
'hideMethod': 'fadeOut'
};
// --- Application code --- //
});
我有一些脚本,并且所有脚本都在toastr.options
声明了toastr.options
。 有没有一种方法(也许使用导入)可以让我全局设置烤面包机选项?
如果要使用es6模块,则可以创建单独的toastr配置。 例如,
import toastr from "toastr";
toastr.options = {
closeButton: true,
debug: true,
newestOnTop: false,
progressBar: true,
positionClass: "toast-top-full-width",
preventDuplicates: false,
onclick: null,
showDuration: "6000",
hideDuration: "1000",
timeOut: "50000",
extendedTimeOut: "1000",
showEasing: "swing",
hideEasing: "linear",
showMethod: "fadeIn",
hideMethod: "fadeOut"
};
export default toastr;
然后只需在顶部而不是toastr
导入该文件,因为这将配置toastr
并导出已配置的toastr
。 如
import toastr from './PathToAboveFile';
或者,如果您想使用es5样式的全局配置,
window.toastrOptions = {...}
在单独的js文件中,并在每个html页面中引用。 然后在$(document).ready
函数中可以进行设置。
toastr.options = window.toastrOptions;
由于现在Toastr选项位于单独的文件中,因此可以对其进行集中配置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.