From 17a1b157a0cd9eb4f805e5c18771c9b8e2bfb97e Mon Sep 17 00:00:00 2001 From: zhixin Date: Wed, 18 Dec 2024 15:18:18 +0800 Subject: [PATCH] Optimize the implementation of the getBootstrapVersion method --- src/utils/index.js | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/utils/index.js b/src/utils/index.js index e7c6ff8ce..778c29bd1 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -2,27 +2,20 @@ export default { getBootstrapVersion () { let bootstrapVersion = 5 - try { - const rawVersion = $.fn.dropdown.Constructor.VERSION + if (typeof window !== 'undefined' && window.bootstrap?.Tooltip.VERSION) { + const rawVersion = window.bootstrap.Tooltip.VERSION - // Only try to parse VERSION if it is defined. - // It is undefined in older versions of Bootstrap (tested with 3.1.1). if (rawVersion !== undefined) { bootstrapVersion = parseInt(rawVersion, 10) } - } catch (e) { - console.error(e) - } - - try { - // eslint-disable-next-line no-undef - const rawVersion = bootstrap.Tooltip.VERSION + } else if (typeof $ !== 'undefined' && $.fn.dropdown?.Constructor.VERSION) { + const rawVersion = $.fn.dropdown.Constructor.VERSION + // Only try to parse VERSION if it is defined. + // It is undefined in older versions of Bootstrap (tested with 3.1.1). if (rawVersion !== undefined) { bootstrapVersion = parseInt(rawVersion, 10) } - } catch (e) { - console.error(e) } return bootstrapVersion