016_解决类中this指向问题

加一句话就能解决问题

this.changeWeather = this.changeWeather.bind(this)

```html <!doctype html>

06_组件实例三大属性1_state.html.html.html

<script type="text/javascript" src="../js/react.development.js"></script>
<!--引入 react-dom ,用于支持react 操作Dom-->
<script type="text/javascript" src="../js/react-dom.development.js"></script>
<!--引入babel,用于将jsx转为js-->
<script type="text/javascript" src="../js/babel.min.js"></script>

</head>

</body> </html>


```html
<!doctype html>
<html lang="`en`">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<script type="text/javascript">
    function demo() {
        console.log(this);
    }

    demo();
    demo.bind({a:1,b:2})
    // 现在什么也么有
    const d =     demo.bind({a:1,b:2})
    d();
    // 这样才行
</script>
</body>
</html>

return

今天天气很{isHot ? '炎热' : '凉爽'}

这个指定的还是原型上的函数

所以还要改一下

image-20210309163313421

```html <!doctype html>

06_组件实例三大属性1_state.html.html.html

<script type="text/javascript" src="../js/react.development.js"></script>
<!--引入 react-dom ,用于支持react 操作Dom-->
<script type="text/javascript" src="../js/react-dom.development.js"></script>
<!--引入babel,用于将jsx转为js-->
<script type="text/javascript" src="../js/babel.min.js"></script>

</head>

</body> </html> ```


results matching ""

    No results matching ""