Yin*_*ang 5 javascript css jquery webpack css-loader
我正在使用带有css-loader的webpack.一切都工作得很好,除了我不知道如何使用jQuery选择一个css-loader转换类.转换后的类名称看起来像"src-styleauthTextboxLeft1Npf4",具有以下css-loader配置:
css?sourceMap&modules&importLoaders=1&localIdentName=[path][name]__[local]__[hash:base64:5]'
Run Code Online (Sandbox Code Playgroud)
这是React代码
const Auth = (props) => {
const toggle = (event) => {
// Working example
$('#container').css('background', 'blue');
// Not working
$(styleCSS.container).css('background', 'green');
};
return (
<div id="container" className={styleCSS.container} onClick={toggle} />
);
};
Run Code Online (Sandbox Code Playgroud)
反正有没有让第二个选择的作品?
如果styleCSS.container是一个类,你只需要.在它前面添加一个。尝试这个:
$('.' + styleCSS.container).css('background', 'green');