Uncaught TypeError: Cannot read property 'trim' of undefined 可以这样写,有值的时候trim,没值的时候为空 let user = this.state.name.trim() || '';