一:子組件不更新問題webpack
第一種 //子組件:點擊事件 handleClick(ev,index){ //提交事件 this.props.onHandleButtonClick(index) //更新子組件渲染 :this.props爲父組件更新的數據 this.componentWillReceiveProps(this.props) } //更新操做 componentWillReceiveProps =(nextProps)=>{ this.setState({ demandType: nextProps.demandType }) } 第二種 //父組件直接定義數據 handleButtonClick(index){ //注意 下面多了一個() this.setState((state)=>({ demandType:tyleList })) }
二:import 訪問路徑再也不須要使用../.../多層查找。web
// webpack.config.js ,設置之後記得從新運行。 module.exports = { resolve:{ extensions:['.js','.jsx'], //添加一下代碼,請注意/app此地址,若是咱們的目錄結果是src爲主目錄則寫src。 alias:{ '@':`${__dirname}/app/` } }, } //調用 import Children from '@/components/Children';