我认为标题说明了一切.每次卸载仍在提取的组件时都会显示黄色警告.
警告:无法在卸载的组件上调用setState(或forceUpdate).这是一个无操作,但是......要修复,取消componentWillUnmount方法中的所有订阅和异步任务.
constructor(props){
super(props);
this.state = {
isLoading: true,
dataSource: [{
name: 'loading...',
id: 'loading',
}]
}
}
componentDidMount(){
return fetch('LINK HERE')
.then((response) => response.json())
.then((responseJson) => {
this.setState({
isLoading: false,
dataSource: responseJson,
}, function(){
});
})
.catch((error) =>{
console.error(error);
});
}
Run Code Online (Sandbox Code Playgroud) 我正在使用Snap.svg API,我需要在CSS中选择三个图形用于样式设置.因此,为了区分它们,我需要给它们一个ID或类名.
这就是我创建元素的方式:
var draw = Snap(100, 75);
c = draw.polyline(0,0, 50,75, 100,0, 0,0);
c.attr({
fill: "black"
});
Run Code Online (Sandbox Code Playgroud)
这是我得到的结果:
<svg height="75" version="1.1" width="100" xmlns="http://www.w3.org/2000/svg">
<polyline points="0,0,50,75,100,0,0,0" style="" fill="#000000"></polyline>
</svg>
Run Code Online (Sandbox Code Playgroud)
这就是我需要的结果:
<svg id="graphic_1" height="75" version="1.1" width="100" xmlns="http://www.w3.org/2000/svg">
<polyline points="0,0,50,75,100,0,0,0" style="" fill="#000000"></polyline>
</svg>Run Code Online (Sandbox Code Playgroud) 我将 Strapi 与 GraphQL 结合使用。我需要查询发布日期晚于当前日期的文章。其背后的目的是允许编辑者发布未来的日期,以便他们可以提前计划。现在我只有这个:
export const ARTICLES_QUERY = gql`
query Articles {
articles(where: { display: true }) {
id
slug
title
publish
display
time_to_read
article_categories {
slug
title
}
user {
username
name
}
cover {
url
}
}
}
`
Run Code Online (Sandbox Code Playgroud)
我想我需要这样的东西:
export const ARTICLES_QUERY = gql`
query Articles($today: String!) {
articles(where: { display: true, publish >= $today }) {
id
slug
...
Run Code Online (Sandbox Code Playgroud)
该字符串的格式是 Strapi 对于日期时间输入的默认格式,结果为"publish": "2020-02-28T02:00:00.000Z"
我知道这不是要走的路,但它说明了我需要完成的事情。