【发布时间】:2019-09-10 09:18:15
【问题描述】:
我有一组全部使用 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 选项?
【问题讨论】:
-
您可以在单独的js中使用export default并导入它或使用window对象来全局设置这个对象。
-
你能给我举个例子吗?
标签: javascript toastr