新增页面保存后,跳转为详情页,同时关闭新增页。

如若依系统,路由 detail/1?type=1,变为 detail/2/1?type=2&id=1

      refreshView() {
        // In order to make the cached page re-rendered
        this.$store.dispatch('tagsView/delCachedView', this.$route).then(() => {
          const { fullPath } = this.$route
          this.$nextTick(() => {
            this.$router.replace({
              path: '/redirect' + fullPath
            })
          })
        })
      },
      // 调用保存接口
      handleSave() {
        const params = this.handleParams()
        this.loading = true
        saveApply(params).then(res => {
          if (res.code === 200) {
            const applyId = res.data?.id || null
            this.loading = false
            if (this.routeType === '1') { // 新增页,保存后,需关闭新增页,跳转至详情页
              this.refreshView()
              // 调用全局挂载的方法,关闭当前页
              this.$store.dispatch('tagsView/delView', this.$route)
              this.$nextTick(() => {
                this.toDetail(applyId) // 跳转至详情页
              })
            } else {
              this.getDetail() // 详情页再次编辑,保存后直接刷新数据
            }
          } else {
            this.$message.error(res.msg)
          }
        }).catch(() => {
        }).finally(() => {
          this.loading = false
        })
      },

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐