1.mounted
1.1mounted中使用$nextTick會導致頁面掛掉
1 mounted() { 2 // 頁面卡死 3 this.$nextTick(() => { 4 this.setUrl() 5 }) 6 }
2.props
2.1props傳過去的值,第一時間在mounted是獲取不到的。因為是異步傳值的。
解決方法:(1)使用watch;(2)將需要進行的處理在父組件進行操作,然后將操作完的值直接傳給子組件。
1 watch: { 2 datas: function (val) { 3 4 } 5 } 6 或 7 (父) 8 <examAchSearchHeader :exprotUrl="exprotUrl"></examAchSearchHeader> 9 ... 10 this.exportUrl = XXXX 11 (子) 12 props: { 13 exportUrl: String 14 }
2.2通過props傳給子組件的值變化后子組件接收到 和 通過refs訪問子組件方法中使用接收到的參數變化的順序問題
通過refs訪問時,接收到的參數是變化前的參數。還是因為異步的問題。可以強制賦值改變,或用watch等。
1 // parent 2 <examAchTable ref="achTable" :dataList="examAchList"></examAchTable> 3 4 // 若這里不強制賦值一下,在examAchList變化后直接調用子組件的transData方法時,子組件dataList仍是變化前的值 5 this.$refs.achTable.dataList = this.examAchList 6 this.$refs.achTable.transData(res.data.totalRecord) 7 8 // child 9 transData(total) { 10 if (this.dataList) 11 // ... 12 }
持續更新中...