Young87

当前位置:首页 >个人收藏

Attempted import error: ‘common‘ does not contain a default export (imported as ‘locationHref‘).

错误的导入方式:
import locationHref from ‘common’
正确的导入方式:
import {locationHref} from ‘common’

原因:
此问题的百度翻译:
“尝试导入错误:“common”不包含默认导出(作为“locationHref”导入)”

/**
 * 浏览器跳转,携带baseName
 * @param href
 * @returns {string|*}
 */
export function locationHref(href) {
    if (href?.startsWith('http')) return window.location.href = href;
    return window.location.href = `${baseName}${href}`;
}

/**
 * 进入首页
 */
export function toHome() {
    // 跳转页面,优先跳转上次登出页面
    const lastHref = window.sessionStorage.getItem('last-href');

    locationHref(lastHref || '/');
}

此文件里包含两个可导出的函数,locationHref只是其中一个,所以正确的导入方式应该表示为,从common文件中导出的肯定是一个函数集合,因此需要大括号,自己则按需导入函数,即其中的子集。

本哪吒才疏学浅,有不对的地方,欢迎大家来杠…

除特别声明,本站所有文章均为原创,如需转载请以超级链接形式注明出处:SmartCat's Blog

上一篇: 一觉醒来2T硬盘数据化为乌有,背后或是两名黑客在竞争式入侵

下一篇: 七、GitHub下载慢,解决GitHub下载慢的问题,用此方法下载速度直接原地起飞

精华推荐