当前位置:   article > 正文

使用this.$router.push()方法页面跳转后不加载列表刷新_this.$router.push 页面不刷新

this.$router.push 页面不刷新

使用this.$router.push()方法页面跳转后不加载列表刷新

注意:created()方法是无效的

方法:在需要刷新的页面添加以下内容

1. 代码实现:

 watch:{
   $route(){
     //跳转到该页面后需要进行的操作
   }
 },
  • 1
  • 2
  • 3
  • 4
  • 5

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)
          }
        })
      },
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

(2)父组件(user-question)
在子组件用this.$emit('refreshDataList', true);无效
所以在父组件使用监听路由的方法

 watch: {
    $route () {
      this.getDataList();
    }
  },
  • 1
  • 2
  • 3
  • 4
  • 5

this.getDataList():是列表查询的方法

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/285107
推荐阅读
相关标签
  

闽ICP备14008679号