问题描述:当我们进行路由跳转时,不触发 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>