我一直在实验流行运动纯,因为动画将不得不使用“参考”,我正在使用它。
这里,为什么ref(number)的值是空的。
import React from 'react'
import {
styler,
tween,
merge,
action,
easing
} from "popmotion";
class Demo extends React.Component {
constructor(props) {
super(props)
this.count = React.createRef();
}
componentDidMount() {
const number = this.count.current.querySelector('#count');
const updateCounter = (v) => {
console.log(v)
return (number.innerHTML = v)
}
tween({
from: 0,
to: 300,
flip: Infinity,
duration: 4000
}).start(updateCounter);
}
render() {
return (
<div>
<p ref={this.count} id='count'></p>
<div id="ball"></div>
</div>
)
}
}
export default Demo它作为TypeError: Cannot set property 'innerHTML' of null返回错误
但是,如果我使用这个文档而不是null,它就可以正常工作了
const number = document.querySelector('#count');有人能带我过去吗。谢谢
发布于 2019-05-15 18:55:41
使用
const number = this.count.current;而不是
const number = this.count.current.querySelector('#count');https://stackoverflow.com/questions/56155845
复制相似问题