我正在使用webpack来管理reactjs项目.我想通过webpack在javascript中加载图像file-loader
.下面是webpack.config.js:
const webpack = require('webpack');
const path = require('path');
const NpmInstallPlugin = require('npm-install-webpack-plugin');
const PATHS = {
react: path.join(__dirname, 'node_modules/react/dist/react.min.js'),
app: path.join(__dirname, 'src'),
build: path.join(__dirname, './dist')
};
module.exports = {
entry: {
jsx: './app/index.jsx',
},
output: {
path: PATHS.build,
filename: 'app.bundle.js',
},
watch: true,
devtool: 'eval-source-map',
relativeUrls: true,
resolve: {
extensions: ['', '.js', '.jsx', '.css', '.less'],
modulesDirectories: ['node_modules'],
alias: {
normalize_css: __dirname + '/node_modules/normalize.css/normalize.css',
}
},
module: {
preLoaders: [
{
test: …
Run Code Online (Sandbox Code Playgroud) 我使用下面的代码在React组件上设置默认道具,但它不起作用.在该render()
方法中,我可以看到输出"未定义道具"已打印在浏览器控制台上.如何为组件道具定义默认值?
export default class AddAddressComponent extends Component {
render() {
let {provinceList,cityList} = this.props
if(cityList === undefined || provinceList === undefined){
console.log('undefined props')
}
...
}
AddAddressComponent.contextTypes = {
router: React.PropTypes.object.isRequired
}
AddAddressComponent.defaultProps = {
cityList: [],
provinceList: [],
}
AddAddressComponent.propTypes = {
userInfo: React.PropTypes.object,
cityList: PropTypes.array.isRequired,
provinceList: PropTypes.array.isRequired,
}
Run Code Online (Sandbox Code Playgroud) 我是python的新手.最近我得到了一个由python编写的项目,它需要一些安装.我运行下面的命令安装但出错了.
# pip install requirements.txt
Collecting requirements.txt
Could not find a version that satisfies the requirement requirements.txt (from versions: )
No matching distribution found for requirements.txt
Run Code Online (Sandbox Code Playgroud)
我在谷歌搜索并找到了这个链接,http://stackoverflow.com/questions/28167987/python-pip-trouble-installing-from-requirements-txt
但我不太明白该帖子中的解决方案.
以下是我的requirements.txt文件:
# cat requirements.txt
ordereddict==1.1
argparse==1.2.1
python-dateutil==2.2
matplotlib==1.3.1
nose==1.3.0
numpy==1.8.0
pymongo==3.3.0
psutil>=2.0
Run Code Online (Sandbox Code Playgroud)
有没有一种简单的方法来安装这个python项目中所有必需的依赖项?
EDIT1
以下是输出pip3 install -r requirements.txt
.
# pip3 install -r requirements.txt
Requirement already satisfied: ordereddict==1.1 in /usr/local/lib/python3.5/dist-packages (from -r requirements.txt (line 1))
Collecting argparse==1.2.1 (from -r requirements.txt (line 2))
Using cached argparse-1.2.1.tar.gz
Collecting python-dateutil==2.2 (from -r requirements.txt …
Run Code Online (Sandbox Code Playgroud) init container
这是 Kubernetes 中的一个很棒的功能,我想知道 docker-compose 是否支持它?它允许我在启动主应用程序之前运行一些命令。
我遇到了这个 PR https://github.com/docker/compose-cli/issues/1499,其中提到支持 init 容器。但我在他们的参考文献中找不到相关文档。
我们使用flyway来管理数据库模式版本,我们正面临一个问题.由于我们作为一个团队工作并使用git作为我们的源代码管理,因此在某些情况下,不同的人会在他们自己的本地存储库上更新数据库模式.如果发生这种情况,我们会得到
检测到已解决的迁移未应用于数据库:2016.03.17.16.46"
时间"2016.03.17.16.46"被另一个人添加,之前我已经应用了一些时间戳.如果发生这种情况,我们必须清理所有数据库表并再次创建它们.我们试图设置错误validateOnMigrate
并做了flywayClean
,但没有任何帮助.还有另一种方法可以改变吗?
我想在mocha测试用例中挂钩之前设置超时值.我知道我可以通过添加-t 10000
mocha的命令行来做到这一点,但这会改变每个测试用例的超时值.我想找到一种方法来以编程方式更改下面的超时是我的代码:
describe('test ', () => {
before((done) => {
this.timeout(10000);
...
Run Code Online (Sandbox Code Playgroud)
它会抱怨线this.timeout(1000)
是timeout
没有定义.如何在挂钩之前设置超时.
我有一个react组件,它呈现一个<input type="file">
dom,允许用户从浏览器中选择图像.我发现当我选择相同的文件时,它的onChange方法没有被调用.经过一些搜索,有人建议使用this.value=null
或return false
在onChange方法的最后,但我尝试它不起作用.
以下是我的代码:
<input id="upload" ref="upload" type="file" accept="image/*"
onChange={(event)=> { this.readFile(event) }}/>
Run Code Online (Sandbox Code Playgroud)
以下是我的尝试:
<input id="upload" ref="upload" type="file" accept="image/*"
onChange={(event)=> {
this.readFile(event)
return false
}}/>
Run Code Online (Sandbox Code Playgroud)
另一个是:
<input id="upload" ref="upload" type="file" accept="image/*"
onChange={(event)=> {
this.readFile(event)
this.value=null
}}/>
Run Code Online (Sandbox Code Playgroud)
我相信上面的解决方案适用于jquery,但我不知道如何让它在reactjs中工作.
我正在使用酶+ mocha + chai来测试我的react-redux项目.酶提供浅层测试组分行为.但我没有找到测试路由器的方法.我正在使用react-router如下:
<Router history={browserHistory}>
...
<Route path="nurse/authorization" component{NurseAuthorization}/>
...
</Route>
Run Code Online (Sandbox Code Playgroud)
我想测试这条路线nurse/authorization
参考NurseAuthorization
组件.如何在reactjs项目中测试它?
EDIT1
我react-router
用作路由器框架.
我创建了一个脚本来启动/停止我的应用程序.现在我想将它添加为centos系统服务.首先,我创建了一个任务来创建从我的脚本到/etc/init.d/service_name的链接,如下所示.
---
- name: create startup link
file: src={{ cooltoo_service_script }} dest={{ cooltoo_service_init }} state=link
Run Code Online (Sandbox Code Playgroud)
创建服务后,我想将其添加到系统服务.用于执行此操作的命令是"chkconfig --add service_name".我想知道是否有一个ansible模块来做,而不是在ansible-playbook文件中硬编码命令.我查看了这个页面http://docs.ansible.com/ansible/service_module.html但它只显示了如何管理服务而不是创建一个新服务.
我有下面的代码,我试图用来lodash
从数组对象中找到最大值;
var a = [ { type: 'exam', score: 47.67196715489599 },
{ type: 'quiz', score: 41.55743490493954 },
{ type: 'homework', score: 70.4612811769744 },
{ type: 'homework', score: 48.60803337116214 } ];
var _ = require("lodash")
var b = _.max(a, function(o){return o.score;})
console.log(b);
Run Code Online (Sandbox Code Playgroud)
输出47.67196715489599
不是最大值.我的代码出了什么问题?
reactjs ×4
javascript ×3
mocha.js ×2
ansible ×1
chai ×1
database ×1
docker ×1
ecmascript-6 ×1
enzyme ×1
flyway ×1
lodash ×1
pip ×1
python ×1
react-router ×1
webpack ×1