如何在React和JSX中导入名称中包含特殊字符的JS文件?
我可以的
import { tomorrow} from 'react-syntax-highlighter/dist/esm/styles/hljs';
(文件夹包含tomorrow.js和tomrorrow-night.js.js)
但我不能:
import { tomorrow-night} from 'react-syntax-highlighter/dist/esm/styles/hljs';
我不认为解构在这里起作用,因为它是一个导入语句。
发布于 2021-10-22 06:00:11
您可以尝试使用
import * as Highlighter from 'react-syntax-highlighter/dist/esm/styles/hljs';
const TomorrowNight = Highlighter[`tomorrow-night`];发布于 2021-10-22 06:00:26
使用import * as blah导入怎么样?这为您提供了一个对象,然后您可以在其中查找任何字符串。
import * as tmrw from from 'react-syntax-highlighter/dist/esm/styles/hljs';
const tmrw_night = tmrw['tomorrow-height']https://stackoverflow.com/questions/69672025
复制相似问题