diff --git a/lib/theme.js b/lib/theme.js index 360dd7e2..4575bc9c 100644 --- a/lib/theme.js +++ b/lib/theme.js @@ -42,7 +42,7 @@ export const initTheme = (theme, changeTheme) => { * 是否优先深色模式, 根据系统深色模式以及当前时间判断 * @returns {*} */ -export function isPreferDark () { +export function isPreferDark() { if (BLOG.APPEARANCE === 'dark') { return true } diff --git a/lib/utils.js b/lib/utils.js index a53b2f2d..be47e17f 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -6,7 +6,7 @@ * @param type js 或 css * @returns {Promise} */ -export function loadExternalResource (url, type) { +export function loadExternalResource(url, type) { return new Promise((resolve, reject) => { let tag @@ -31,8 +31,8 @@ export function loadExternalResource (url, type) { * @param {}} variable * @returns */ -export function getQueryVariable (variable) { - const query = window.location.search.substring(1) +export function getQueryVariable(variable) { + const query = typeof window !== 'undefined' ? window.location.search.substring(1) : '' const vars = query.split('&') for (let i = 0; i < vars.length; i++) { const pair = vars[i].split('=') @@ -46,7 +46,7 @@ export function getQueryVariable (variable) { * @param target * @param sources */ -export function mergeDeep (target, ...sources) { +export function mergeDeep(target, ...sources) { if (!sources.length) return target const source = sources.shift() @@ -68,6 +68,6 @@ export function mergeDeep (target, ...sources) { * @param item * @returns {boolean} */ -export function isObject (item) { +export function isObject(item) { return (item && typeof item === 'object' && !Array.isArray(item)) }