我正在尝试在React JSX文件中使用Foundation创建一个简单的双列页面。我已经导入了SCSS文件并测试了一些功能(即按钮,这是正确的程式化),但我无法让两列并排排列。有什么想法为什么这些列堆叠而不是并排坐着?
我的index.jsx文件
var React = require('react');
var ReactDOM = require('react-dom');
require('jquery');
import './styles/app.scss';
// Load foundation
require('style-loader!css-loader!foundation-sites/dist/css/foundation.min.css');
$(document).foundation();
class Markdown extends React.Component {
render() {
return (
<div className="container">
<div className="row">
<div className="small-6 columns">6 columns</div>
<div className="small-6 columns">6 columns</div>
<button className="success button">Test</button>
</div>
</div>
)
}
}
ReactDOM.render(<Markdown />, document.getElementById('app'));
我的app.scss文件:
@import "base/variables";
//Foundation
@import "base/foundation-settings";
@import "foundation";
@include foundation-everything;
我的webpack.config.js文件:
const webpack = require('webpack');
const path = require('path');
module.exports = {
entry: [
'script-loader!jquery/dist/jquery.min.js',
'script-loader!foundation-sites/dist/js/foundation.min.js',
'./app/index.jsx'
],
externals: {
jquery: 'jQuery'
},
plugins: [
new webpack.ProvidePlugin({
'$': 'jquery',
'jQuery': 'jquery'
})
],
output: {
path: __dirname,
filename: 'bundle.js'
},
resolve: {
alias: {
},
extensions: ['*', '.js', '.jsx']
},
module: {
rules: [{
test: /\.scss$/,
use: [{
loader: "style-loader" // creates style nodes from JS strings
}, {
loader: "css-loader" // translates CSS into CommonJS
}, {
loader: "sass-loader", // compiles Sass to CSS
options: {
sourceMap: true,
includePaths: [
path.resolve(__dirname, './node_modules/foundation-sites/scss'),
]
}
}]
}, {
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
options: {
presets: ['react', 'es2015']
}
}]
}
};
控制台中没有错误,基础CSS显示在DOM中。
尝试将app.scss文件更改为包含基础网格,如下所示:
@import "base/variables";
//Foundation
@import "base/foundation-settings";
@import "foundation";
@include foundation-everything;
// Not included in foundation-everything:
@include foundation-grid;
我们的入门项目包括完整的导入列表,可以轻松地注释掉您不需要的组件。完整列表也包括在下面。 @import'基金会';
@include foundation-global-styles;
@include foundation-xy-grid-classes;
// @ include foundation-grid;
// @ include foundation-flex-grid;
@include foundation-flex-classes;
...
出于同样的原因,我在桌子上敲打着我的头,与你几乎一样的设置,碰巧偶然发现了技术文档中的这个小小的暗示。无论出于何种原因,如果你想要它们,除了“基础 - 一切”之外,还需要导入“基础网格”和“基础 - 柔性网格”。
我希望这有帮助!
对我来说,要使基础工作,我必须把它
componentDidMount() {
$(document).foundation();
}
在根组件中。
另外,要使用jquery,我必须运行const $ = window.$;