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

首页 / 新闻资讯 / 正文

首先要配置好路由

在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'],    }