![](/img/trans.png)
[英]How can I use all import, modules.export, and export in the same ts file?
[英]How can I import all export consts at the same time?
export const getURLPath = (url) => url.split('.com')[1]
export const getSectionName = (path) => path.split('/butik/liste')[1]
export const getIdByName = (sectionName) => sectionMapping.find(item => item.name.toLowerCase() == sectionName).id
export const getNameById = (sectionId) => sectionMapping.find(item => item.id == sectionId).name.toLowerCase()
export const getContentIdFromURL = (path) => path.split('-p-').pop().split('?')[0];
export const getBoutiqueIdFromURL = (path) => path.split('boutiqueId=').pop().split('&')[0];
export const getMerchantIdFromURL = (path) => path.split('merchantId=').pop().split('&')[0];
我想導入右側的所有功能。 我想用他們的純名字。 例如: getURLPath() 就像這樣,沒有前綴等。我怎么做?
export default { getURLPath : (url) => url.split('.com')[1], getSectionName : (path) => path.split('/butik/liste')[1], getIdByName : (sectionName) => sectionMapping.find(item => item.name.toLowerCase() == sectionName).id, getNameById : (sectionId) => sectionMapping.find(item => item.id == sectionId).name.toLowerCase(), getContentIdFromURL : (path) => path.split('-p-').pop().split('?')[0], getBoutiqueIdFromURL : (path) => path.split('boutiqueId=').pop().split('&')[0], getMerchantIdFromURL : (path) => path.split('merchantId=').pop().split('&')[0], }
如果您不想要utils.getURLPath
語法,那么唯一的方法就是將它們全部拼寫出來,即
import {getURLPath, getSectionName, getIdByName, getNameById, /* etc ... */} from '../utils';
你可以使用這樣的東西:
export const fun1...;
export const fun2...;
...
// This is not even mandatory I think but leaves u the choice to use prefix at some point. As u wish
export default {
fun1,
fun2,
}
然后將它們導入到您的其他文件中,例如:
import {
fun1,
fun2,
...
} from '/your/file';
// Then use them
fun1();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.