Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何找到可以从npm包导出的内容_Javascript_Reactjs_D3.js_Npm_Timer - Fatal编程技术网

Javascript 如何找到可以从npm包导出的内容

Javascript 如何找到可以从npm包导出的内容,javascript,reactjs,d3.js,npm,timer,Javascript,Reactjs,D3.js,Npm,Timer,我正试图复制这个 我已经用npm安装了d3定时器包 它肯定在那里,因为我已经阅读了文件 我所困惑的是如何将计时器导入到我的代码中。在codepen上的代码中,它只使用了d3.timer,但没有显示上面的导入。所以我尝试导入d3,但在d3定时器包中找不到它。我试过定时器,定时器,D3,D3 因此,我的问题是——我如何着手调查该方案,以确定出口产品的名称 或者,如果这太复杂了——在这种特殊情况下,我应该导入什么来获得d3.timer的功能 非常感谢 代码笔中的代码: const Component

我正试图复制这个

我已经用npm安装了d3定时器包

它肯定在那里,因为我已经阅读了文件

我所困惑的是如何将计时器导入到我的代码中。在codepen上的代码中,它只使用了d3.timer,但没有显示上面的导入。所以我尝试导入d3,但在d3定时器包中找不到它。我试过定时器,定时器,D3,D3

因此,我的问题是——我如何着手调查该方案,以确定出口产品的名称

或者,如果这太复杂了——在这种特殊情况下,我应该导入什么来获得d3.timer的功能

非常感谢

代码笔中的代码:

const Component = React.Component;

const Ball = ({ x, y }) => (
  <circle cx={x} cy={y} r={5} />
);

const MAX_H = 750;

class App extends Component {
  constructor() {
    super();

    this.state = {
      y: 5,
      vy: 0
    }
  }

  componentDidMount() {
    this.timer = d3.timer(() => this.gameLoop());
    this.gameLoop();
  }

  componentWillUnmount() {
    this.timer.stop();
  }

  gameLoop() {
    let { y, vy } = this.state;

    if (y > MAX_H) {
      vy = -vy*.87;
    }

    this.setState({
      y: y+vy,
      vy: vy+0.3
    })

  }

  render() {
    return (
      <svg width="100%" height={MAX_H}>
        <Ball x={50} y={this.state.y} />
      </svg>
    )
  }
}

ReactDOM.render(<App />, document.getElementById('app'));
const Component=React.Component;
常数球=({x,y})=>(
);
常数MAX_H=750;
类应用程序扩展组件{
构造函数(){
超级();
此.state={
y:5,
vy:0
}
}
componentDidMount(){
this.timer=d3.timer(()=>this.gameLoop());
这个.gameLoop();
}
组件将卸载(){
this.timer.stop();
}
gameLoop(){
设{y,vy}=this.state;
如果(y>最大值){
vy=-vy*.87;
}
这是我的国家({
y:y+vy,
vy:vy+0.3
})
}
render(){
返回(
)
}
}
ReactDOM.render(,document.getElementById('app'));
我的代码

import React from 'react';
import d3 from 'd3-timer'

const Component = React.Component;


const Ball = ({ x, y }) => (
    <circle cx={x} cy={y} r={5} />
);

const MAX_H = 750;

export default class App extends Component {
  constructor() {
    super();

    this.state = {
      y: 5,
      vy: 0
    }
  }

  componentDidMount() {
    this.timer = d3.timer(() => this.gameLoop());
    this.gameLoop();
  }

  componentWillUnmount() {
    this.timer.stop();
  }

  gameLoop() {
    let { y, vy } = this.state;

    if (y > MAX_H) {
      vy = -vy*.87;
    }

    this.setState({
      y: y+vy,
      vy: vy+0.3
    })

  }

  render() {
    return (
        <svg width="100%" height={MAX_H}>
          <Ball x={50} y={this.state.y} />
        </svg>
    )
  }
}

从“React”导入React;
从“d3定时器”导入d3
常量组件=React.Component;
常数球=({x,y})=>(
);
常数MAX_H=750;
导出默认类应用程序扩展组件{
构造函数(){
超级();
此.state={
y:5,
vy:0
}
}
componentDidMount(){
this.timer=d3.timer(()=>this.gameLoop());
这个.gameLoop();
}
组件将卸载(){
this.timer.stop();
}
gameLoop(){
设{y,vy}=this.state;
如果(y>最大值){
vy=-vy*.87;
}
这是我的国家({
y:y+vy,
vy:vy+0.3
})
}
render(){
返回(
)
}
}
错误消息:

尝试导入错误:“d3计时器”不包含默认导出(作为“d3”导入)。

请重试


从'd3 timer'导入{timer}
然后使用
timer()

没有d3模块,只有d3 timer,它包含与d3.timer等效的功能,但不知道如何导入我的答案。谢谢!我缺少的是那些花括号。看起来我需要了解命名导出和默认导出之间的区别