要放到state里面用setState去替换
import React from 'react'
export default class App extends React.Component {
// 关键字state
state={
mytext:"收藏",
myShow:true
}
render() {
return (
<div>
<h1>欢迎来到react开发</h1>
<button onClick={()=>{
// 修改变量
this.setState({
myShow:!this.state.myShow
})
if(this.state.myShow){
console.log("收藏逻辑")
}
else{
console.log("取消收藏逻辑")
}
}}>{this.state.myShow?"收藏":"取消收藏"}</button>
</div>
)
}
}
标签:状态,console,变量,收藏,state,myShow,log,替换,setState From: https://www.cnblogs.com/kaibindirver/p/17351879.html