[英]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.