在我的script.js中:
pic.src = "/static/photos/1.jpg"; // This works
pic2.src = "{% static 'photos/1.jpg' %}" // Does not work
Run Code Online (Sandbox Code Playgroud)
为什么世界会发生这种情况?因为在我的home.html中,{%static'路径'%}有效:
{% load staticfiles %}
<script src="{% static 'script.js' %}"></script> // This works
Run Code Online (Sandbox Code Playgroud)
是{%load staticfiles%}还是{%load static%}?这两个都适用于我,script.js已加载.
我知道setState()不会立即变异this.state.因此,在下面的代码中,单击按钮后总是取消选中复选框.如何解决这个问题?
handleClick = () => {
this.setState({tick: !this.state.tick})
}
render() {
return (
<button type='button' onClick={() => this.handleClick()} >
<input type="checkbox" value={this.state.tick} />
Tick here
</button>
)
}
Run Code Online (Sandbox Code Playgroud)