【发布时间】:2019-10-13 13:20:31
【问题描述】:
试图在 react js applciation 中导入 css 但它抛出错误
这是一个仪表板应用程序,其中节点 js 在服务器端并在客户端做出反应 js
webpack.base.js
module.exports = {
//Running babel to every file
module: {
rules: [
{
test: /\.js?$/,
loader: 'babel-loader',
exclude: /node_modules/,
options: {
presets: [
'react',
'stage-0',
['env', { targets: { browsers: ['last 2 versions'] } }]
]
}
}, {
test: /\.css$/,
loader: "style-loader!css-loader"
}, {
test: /\.(jpe?g|png|gif|woff|woff2|eot|ttf|svg)(\?[a-z0-9=.]+)?$/,
loader: 'url-loader?limit=100000'
}
]
}//end module
}
style.css
.segment {
border-top:14px solid #14a767;
border-bottom: 3px solid #14a767;
margin: 2px 2px 2px 140px;
width: 80%
}
Home.js(组件)
import '../../css/style.css'
return window && document && document.all && !window.atob;
^
ReferenceError: 窗口未定义
【问题讨论】:
-
你想达到什么目的?该错误与您的CSS无关,它与您的JS代码有关...
-
你把
return window && document && document.all && !window.atob;放在组件里面的什么地方 -
@Tenusha :: ``` 返回窗口 && 文档 && document.all && !window.atob; ```这是错误
-
如果你在这样的函数中使用它,
f1 = function(){ return window && document && document.all && !window.atob }。会执行成功,返回HTMLAllCollection对象。 -
现在可以正常工作了 :-) 谢谢@Tenusha..