0

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

我可以

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

(该文件夹包含明天.js 和 tomrorrow-night.js)

但我不能:

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

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

4

2 回答 2

2

你可以试试

import * as Highlighter from 'react-syntax-highlighter/dist/esm/styles/hljs';

const TomorrowNight = Highlighter[`tomorrow-night`];
于 2021-10-22T06:00:11.433 回答
2

如何使用import * as blah导入?这为您提供了一个对象,然后您可以在其中查找任何字符串。

import * as tmrw from from 'react-syntax-highlighter/dist/esm/styles/hljs';
const tmrw_night = tmrw['tomorrow-height']
于 2021-10-22T06:00:25.800 回答