vue更新数据后重新请求数据并刷新页面

2022年12月9日08:56:27

首先要配置好路由

在app.vue添加下面代码

export default {
  provide() {
    return {
      reload: this.reload,
    }
  },
  data() {
    return {
      isRouterAlive: true,
    }
  },
  methods: {
    reload() {
      this.isRouterAlive = false
      this.$nextTick(function() {
        this.isRouterAlive = true
      })
    },
  },
}

并在template引入

<router-view v-if="isRouterAlive"/>

在需要触发的方法下添加

this.reload()

       submitUpload() {
        dianjiAPI(formdata).then(res=>{
          this.$message({
          message: res.data,
          type: 'success'
        });
        //清空上传列表
        this.$refs.upload.clearFiles()
        //刷新页面
        this.reload()
        })
        
      },

在下面添加 inject: ['reload']

export default{
      inject: ['reload'],
   }

  • 作者:沐雨~橙风
  • 原文链接:https://blog.csdn.net/qq_43761240/article/details/124929489
    更新时间:2022年12月9日08:56:27 ,共 490 字。