Attempted import error: ‘common‘ does not contain a default export (imported as ‘locationHref‘).
日期: 2021-07-01 分类: 个人收藏 855次阅读
错误的导入方式:
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
精华推荐