如果你在开发移动端 app/h5 页面,那么肯定会遇到这样的问题
详情页返回列表,不做任何修改的情况,应当保持之前的状态
详情页返回列表,有修改的情况,应当自动刷新保持最新状态
让我们封装一个 hooks
import { isPlainObject } from 'lodash'
import { emitShell } from '@/plugins/shellBus'
export interface BackPageParams {
isCalled: boolean
params: Recordable
}
export const backParams: BackPageParams = {
isCalled: false,
params: {}
}
export const useBackPage = () => {
return (params?) => {
backParams.isCalled = true
backParams.params = isPlainObject(params) ? params : {}
return emitShell('onBackPress')
}
}
使用时只需要通过传参就可以实现你想要的效果
backPage({ needResetList: true })
backPage()