使用this.$router.push()方法页面跳转后不加载列表刷新
注意:created()方法是无效的
方法:在需要刷新的页面添加以下内容
1. 代码实现:
watch:{
$route(){
//跳转到该页面后需要进行的操作
}
},
2. 示例:
(1)子组件
onSubmit () {
this.$http[!this.form.id ? 'post' : 'put']('/cd/question', {...this.form}).then(({ data: res }) => {
if (res && res.code === 0) {
this.$message({
message: '操作成功',
type: 'success',
duration: 500,
onClose: () => {
}
})
this.$router.push({ name: 'user-question' })
} else {
this.$message.error(res.msg)
}
})
},
(2)父组件(user-question)
在子组件用this.$emit('refreshDataList', true);
无效
所以在父组件使用监听路由的方法
watch: {
$route () {
this.getDataList();
}
},
this.getDataList()
:是列表查询的方法