topic description
this.props.name is not displayed, but the event triggered by onclick is valid, which changes the value of name to "ls"
. < H1 > written as class class cannot be fetched < / H1 >
import {observable,action,computed} from "mobx"
class TodoList {
@observable name = "hi"
@action change(){
console.log("change")
this.name = "ls"
}
}
export default new TodoList()
< H1 > problem: P tag cannot get a value < / H1 >
@observer
class App extends React.Component {
render() {
return (
{this.props.todoList.name}
//
)
}
}
export default App;
< H1 > but if TodoList writes like this, the p tag can take the value < / H1 >
export default new TodoList("zs")
let TodoList = observable({
name :"hi",
change(){
this.name = "ls"
}
})
export default TodoList