亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

TypeError: undefined is not an object in

TypeError: undefined is not an object in

慕碼人2483693 2022-10-21 10:14:21
我對 Javascript 和 ReactJS 真的很陌生,并且對錯誤感到困惑TypeError: undefined is not an object (evaluating '_this.state = { destination: '' }')這是我的代碼:import React, {Component} from 'react';import { StyleSheet, View, TextInput } from 'react-native';export default class SearchBar extends Component {    constructor() {        /*        this.state = {            destination: ''        };        */        super();    }    render() {        return (            <View style={styles.inputContainer}>                <TextInput                    style={styles.input}                />            </View>        );    }}這段代碼工作正常。但是一旦我取消評論this.state = {            destination: ''        };我得到了錯誤。為什么它在困擾我undefined?我沒有在任何地方訪問它。這可能看起來像這里問題的重復, 但不同之處在于,在該問題中,解決方案涉及.bind(this)在提問者定義的函數上使用。我沒有這樣的功能,我可以調用它。任何幫助將不勝感激。
查看完整描述

1 回答

?
慕的地10843

TA貢獻1785條經驗 獲得超8個贊

this由 配置super。執行之前super,this尚未配置。這就是您遇到問題的原因。使固定:


constructor(props) {

    super(props);

    this.state = {

        destination: ''

    };

}


查看完整回答
反對 回復 2022-10-21
  • 1 回答
  • 0 關注
  • 281 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號