反应:未定义no-undef

时间:2019-09-11 10:30:13

标签: reactjs

当我刷新clearAll()中的错误消息是:

./ src / App.js

第22行:未定义“注释” no-undef

第23行:未定义“注释” no-undef

如何定义要使用的属性>

import React, { Component } from 'react';
import Route from 'react-router-dom';
import './App.css';
import Header from './components/Header';
import Router from './components/Router';
import Home from '.Home';
import AddNote from '/AddNote';
import EditNote from '/EditNote';


class App extends React.Component {

constructor(props) {
    super(props);
    this.state = {
        note: "",
        notes: []
    };
}

clearAll() {
    notes.length = 0;
    notes = [];
}

2 个答案:

答案 0 :(得分:0)

notenotes保存在组件状态,您可以分别通过this.state.notethis.state.notes在组件中访问它们。

答案 1 :(得分:0)

const {note,notes} = this.state;

相关问题