小编Ale*_*kov的帖子

防止组件使用React-router卸载

对于React-Router组件,我很沮丧.但是当我浏览链接时,我无法找到解释为什么我的组件会被卸载的原因?以及如何预防呢?

在我的示例中,我有一个包含计时器和重新呈现内容的组件

我收到一个错误:

在此输入图像描述

这是ReactJS代码:

/*global define, Backbone, React, $, Request, Router, Route, Link */

var App = React.createClass({
    render: function () {
        return (
            <div>
                <h1>App</h1>
                <ul>
                    <li><Link to="/about">About</Link></li>
                    <li><Link to="/timer">Timer</Link></li>
                </ul>
                {this.props.children}
            </div>
        )
    }
});

var About = React.createClass({
    render: function () {
        return <h3>Here is about page</h3>
    }
});

var Timer = React.createClass({
    getInitialState: function() {
        return {counter: 0};
    },
    render: function () {
        return (
            <div>
                <h2>Time is running over...</h2>
                <b>{this.props.interval}</b>
                <p>{this.state.counter}</p>
            </div>
        ) …
Run Code Online (Sandbox Code Playgroud)

reactjs react-router

8
推荐指数
2
解决办法
5184
查看次数

'npm test'的Jest失败,"在严格模式下使用const"

我只是想使用Jest作为单元测试框架.我从官方的ReactJS方面做了一些示例.

function sum(value1, value2) {
  return value1 + value2;
}
module.exports = sum;
----------------------------------------------------------------
jest.dontMock('../sum');

describe('sum', function() {
 it('adds 1 + 2 to equal 3', function() {
   var sum = require('../sum');
   expect(sum(1, 2)).toBe(3);
 });
});
Run Code Online (Sandbox Code Playgroud)

但是当我运行npm测试时,我得到了下一个错误:

/home/app.local/node_modules/jest-cli/bin/jest.js:12
const fs = require('fs');
^^^^^
SyntaxError: Use of const in strict mode.
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:902:3
npm ERR! Test failed.  See above for more details. …
Run Code Online (Sandbox Code Playgroud)

node.js npm jestjs

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

如何缩放到Openlayers3(v3.17.1)地图的任何功能

我知道这个问题已经在其他许多主题中进行了讨论。但是我仍然找不到解决我问题的方法。没有收据适合我。

问题很简单。我在Openlayers3(v3.17.1)地图上有一个功能。我应该能够缩放到我想要的任何功能。

变焦前:

在此处输入图片说明

缩放后:

在此处输入图片说明

如前所述,我使用的是v3.17.1版本。

var features = myLayer.getSource().getFeatures();
var myFirstFeature = features[0];
Run Code Online (Sandbox Code Playgroud)

选项1:

map.zoomToExtent(feature.geometry.getBounds());
Run Code Online (Sandbox Code Playgroud)

选项2:

    var bounds = f.geometry.getBounds().clone();
    this._map.zoomToExtent(bounds,false);
Run Code Online (Sandbox Code Playgroud)

openlayers-3

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

标签 统计

jestjs ×1

node.js ×1

npm ×1

openlayers-3 ×1

react-router ×1

reactjs ×1