Javascript 不支持八位字节文字的样式化组件

Javascript 不支持八位字节文字的样式化组件,javascript,styled-components,Javascript,Styled Components,下面的代码似乎不能与样式化组件一起工作 const currencyMap = { inr: ' \\20B9 ', }; export const CurrencyIcon = styled.span` &:after { content: ${props => currencyMap[props.currency]}; } `; 在那里,好像它被改为跟随,它工作得非常好 export const CurrencyIcon = styl

下面的代码似乎不能与样式化组件一起工作

const currencyMap = {
    inr: ' \\20B9 ',
};

export const CurrencyIcon = styled.span`
    &:after {
        content: ${props => currencyMap[props.currency]};
    }
`;
在那里,好像它被改为跟随,它工作得非常好

export const CurrencyIcon = styled.span`
    &:after {
        content: ' \\20B9 ';
    }
`;

是否有人遇到过类似的问题并解决了此问题。

styled component将模板字符串中的文本原样转换。如果仔细观察,内容css属性将作为字符串提供。所以模板字符串也应该有引号,样式化组件在生成css时不会添加引号。像这样的

export const CurrencyIcon = styled.span`
    &:after {
        content: '${props => currencyMap[props.currency]}';
    }
`;

虽然所有其他css属性都有文字值,但内容可以有不同类型的值,字符串就是其中之一

样式化组件按原样转换模板字符串中的文本。如果仔细观察,内容css属性将作为字符串提供。所以模板字符串也应该有引号,样式化组件在生成css时不会添加引号。像这样的

export const CurrencyIcon = styled.span`
    &:after {
        content: '${props => currencyMap[props.currency]}';
    }
`;
虽然所有其他css属性都有文字值,但内容可以有不同类型的值,字符串就是其中之一