小编kur*_*kan的帖子

Styled-Components:指定父项悬停时子项的样式

我有一个简单的组件以下是它的2个版本 - 有和没有样式组件:

没有样式组件

<div id="container">
    <div id="kid"></div>
</div>


#container {
    width: 100px;
    height: 100px;
}

#kid {
    width: 20px;
    height: 20px;
}

#container:hover #kid{
    background: green;
}
Run Code Online (Sandbox Code Playgroud)

使用样式组件

const Container = styled.div`
    width: 100px;
    height: 100px;
`;

const Kid = styled.div`
    width: 20px;
    height: 20px;
`;

<Container>
    <Kid />
</Container
Run Code Online (Sandbox Code Playgroud)

如何在前一个示例中的悬停行为上实现相同的功能?

css reactjs styled-components

10
推荐指数
2
解决办法
1万
查看次数

Axios post request.body是空对象

我试图从我的反应中发布数据.后端 - 表达.这是后端代码:

var express = require('express');
var app = express();
var bodyParser = require("body-parser");
var  methodOverride = require("method-override");
var mongoose = require("mongoose");
var expressSanitizer = require("express-sanitizer");

mongoose.connect("mongodb://localhost/blog-react");

//app config
app.set("view engine", "ejs");
app.use(express.static("public"));
app.use(bodyParser.urlencoded({extended: true}));
//must be after parser
app.use(expressSanitizer());
app.use(methodOverride("_method"));

//schema config
var blogSchema = new mongoose.Schema({
    title: String,
    image: String,
    body: String,
    //it should be date. With default value now.
    created: {
        type: Date, default: Date.now
    }
});

var Blog = mongoose.model("Blog", blogSchema);


function handle500(response, error){
    console.log(error.stack); …
Run Code Online (Sandbox Code Playgroud)

node.js express reactjs axios

9
推荐指数
2
解决办法
9956
查看次数

Enzyme需要配置适配器,但没有找到

我在调用enzym's mount函数时遇到问题.它说:

Enzyme Internal Error: Enzyme expects an adapter to be configured, but found none. To
      configure an adapter, you should call `Enzyme.configure({ adapter: new Adapter() })`
      before using any of Enzyme's top level APIs, where `Adapter` is the adapter
      corresponding to the library currently being tested. For example:

      import Adapter from 'enzyme-adapter-react-15';
Run Code Online (Sandbox Code Playgroud)

我的setupTests.js文件看起来像这样:

import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

configure({ adapter: new Adapter() });
Run Code Online (Sandbox Code Playgroud)

并在package.json中:

"jest": {
    "testEnvironment": "jest-environment-jsdom-global",
    "setupFiles": [ …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs jestjs enzyme

9
推荐指数
1
解决办法
3353
查看次数

React ProptTypes - 对象的对象

我有一个对象,它有动态键(但值是具有相同键的对象):

menu = {
    dogs: {
        name: 'some name1',
        url: 'google.com'
    },
    cats: {
        name: 'some name2',
        url: 'facebook.com'
    },
    parrots: {
        name: 'some name3',
        url: 'linkedin.com'
    }
}
Run Code Online (Sandbox Code Playgroud)

假设我有一个组件:

const Menu = ({menu}) => (
    <div>        
        {
            Object.keys(menu).map(key => (
                <div>{menu.name}</div>
            ))
        }
    </div>
);
Run Code Online (Sandbox Code Playgroud)

如何使用PropTypes验证菜单道具?

reactjs react-proptypes

6
推荐指数
1
解决办法
953
查看次数

匿名类的方法出乎意料地行为

public class Solution {
    private String name;

    Solution(String name) {
        this.name = name;
    }

    private String getName() {
        return name;
    }

    private void sout() 
    {
        new Solution("sout")
        {
            void printName() 
            {
                System.out.println(getName());
            }
        }.printName();
    }

    public static void main(String[] args) {
        new Solution("main").sout();
    }
}
Run Code Online (Sandbox Code Playgroud)

匿名类的方法出乎意料地行为.如何制作方法sout打印"sout",现在打印"main"?

java

5
推荐指数
1
解决办法
100
查看次数

axios - 如何处理大整数

这是我的要求:

    axios.get(url)
    .then(res => {
        console.log(res.data)
    })
Run Code Online (Sandbox Code Playgroud)

输出是{ value: 156144277082605255 }

但应该是{ value: 156144277082605250 }

在这种情况下如何处理大整数?我尝试使用json-bigint 但由于我从 axios 获取 response.data 作为对象 - 它没有帮助。

javascript bigint axios

4
推荐指数
1
解决办法
9215
查看次数

无法在ubuntu上运行python3

我无法在ubuntu 14.04上运行python3

alias python=python3
python --version
Run Code Online (Sandbox Code Playgroud)

输出:

Python 2.7.6
Run Code Online (Sandbox Code Playgroud)

python3 --version
Run Code Online (Sandbox Code Playgroud)

给出相同的输出

据我所知,python3应该预先安装在系统上?

我试着跑:

sudo apt-get install python3
Run Code Online (Sandbox Code Playgroud)

但是有一个错误:

  Setting up idle-python3.4 (3.4.3-1ubuntu1~14.04.3) ...
  File "/usr/lib/python3.4/compileall.py", line 120
    print('*** ', end='')
                     ^
SyntaxError: invalid syntax
dpkg: error processing package idle-python3.4 (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 idle-python3.4
Run Code Online (Sandbox Code Playgroud)

python ubuntu python-2.7 python-3.x

1
推荐指数
1
解决办法
1372
查看次数

React Js 前端和 Express 后端 - 无法正确加载静态文件

我在前端有一个 React 应用程序。以下是路线:

    var React = require("react");
    var ReactDOM = require("react-dom");
    var {Route, Router, IndexRoute, browserHistory} = require("react-router");
    var Main = require("Main");
    var BlogList = require('BlogList');
    var Blogpost = require('Blogpost');
    var NewBlog = require('NewBlog');
    var EditBlog = require('EditBlog');
    var NotFound404 = require('NotFound404');


    ReactDOM.render(    
        <Router history={browserHistory}>   
            <Route path="/" component={Main}>
                <IndexRoute component={BlogList} />     
                <Route path="blogs/new" component={NewBlog} />          
                <Route path="blogs/:id/edit" component={EditBlog} />                        
                <Route path="blogs/:id" component={Blogpost} /> 
                <Route path='404' component={NotFound404} />
                <Route path='*' component={NotFound404} />          
            </Route>        
        </Router>, 

        document.getElementById("app")
    );
Run Code Online (Sandbox Code Playgroud)

这是public目录中的index.html :

    <!DOCTYPE …
Run Code Online (Sandbox Code Playgroud)

javascript express reactjs

1
推荐指数
1
解决办法
2129
查看次数