問題描述:當我們進行路由跳轉時,不觸發 mounted 時,首先想到的就是使用 keep-alive 進行了路由緩存,如果再次進入到緩存的路由頁面時,我們可以觸發 activated 的生命週期,這樣同樣可以進行相應的操作。但是今天我並不是想要說 keep-alive 的生命週期鉤子函數,而只是記錄下平時我們很容易忽略的一些知識點。
我們對新增或者修改跳轉到不同的路由,只是傳參不同。
handleAdd (type, row = {}) {
let param = ``
if (type === 'copy') {
param = `&capacityId=${row.id}`
}
this.$router.push({
path: `/capacityPool/list/addInquiry?type=${type}${param}`,
})
},
根據不同的參數,渲染不同的組件。
<script>
import Create from './components/create'
import Detail from './components/idetail'
export default {
components: {
Create,
Detail,
},
render () {
const type = this.$route.query.type
return (
<div>
{(type === 'create' || type === 'edit') && <Create/>}
{type === 'detail' && <Detail/> }
</div>
)
},
}
</script>