【发布时间】:2019-04-19 18:30:42
【问题描述】:
我正在努力找出为什么我的按钮在单击它时不发出声音。 console.log() 测试工作正常,但 -part 不行。我也尝试了一些 npm-packets 来解决这个问题,但我的代码似乎有一个普遍的问题。它出什么问题了?有人可以帮我吗?
main.js:
import Button from './button';
class Drumpad extends Component {
constructor(props) {
super(props);
this.state = {
Q:
{
id: 'Q',
name: 'Q',
src: 'https://s3.amazonaws.com/freecodecamp/drums/Heater-1.mp3'
},
}
}
render() {
return (
<div style={test}>
<div id='row1'>
<Button cfg={this.state.Q}/>
</div>
</div>
)
}
}
还有 button.js:
class Button extends Component {
constructor(props) {
super(props);
this.state = {
}
}
handleClick = () => {
console.log(this.props.cfg.src);
return (
<audio ref='audioClick' src={this.props.cfg.src} type='audio/mp3' autoPlay>
);
};
render() {
return (
<div>
<button style={buttonStyle} onClick={this.handleClick}>
<h1>{this.props.cfg.name}</h1>
</button>
</div>
)
}
}
【问题讨论】:
-
嘿 Brune,这不是一份报告,而是一个友好的标签,以便您和其他人可以参考之前提出的与您的问题类似的问题。这就是 stackoverflow 的工作原理,希望您阅读指南?