如何在 React 和 JSX 中导入名称中包含特殊字符的 JS 文件?



如何在React和JSX中导入具有特殊字符的JS文件?

我可以

import { tomorrow} from 'react-syntax-highlighter/dist/esm/styles/hljs';

(文件夹中包含tomorrow.js和tomorrow -night.js)

但我不能:

import { tomorrow-night} from 'react-syntax-highlighter/dist/esm/styles/hljs';

我认为析构在这里不起作用,因为它是一个import语句。

你可以试试

import * as Highlighter from 'react-syntax-highlighter/dist/esm/styles/hljs';
const TomorrowNight = Highlighter[`tomorrow-night`];

如何使用import * as blah导入?这给了你一个对象,你可以在其中查找任何字符串。

import * as tmrw from from 'react-syntax-highlighter/dist/esm/styles/hljs';
const tmrw_night = tmrw['tomorrow-height']

最新更新