Ver código fonte

fix(frontend): 服务角色申请页返回按钮改用方法调用,修复 uni is not defined

模板里直接写 @click="uni.navigateBack",小程序渲染阶段组件实例上没有 uni,
触发 "Property or method uni is not defined on the instance but referenced
during render";紧接着 render 抛
TypeError: Cannot read properties of undefined (reading 'navigateBack'),
该页渲染中断。

改为 goBack() 方法:页面栈深 > 1 时 navigateBack,否则 switchTab 回首页
(按钮文案是「返回首页」,深链进入或单页栈时 navigateBack 会失败)。

全仓已扫:模板中直接用 uni./wx./getApp/getCurrentPages 的仅此一处,
wx.* 的其余命中均为 v-for="wx in ..." 循环变量。
liaoxg 5 dias atrás
pai
commit
bcc6f1a808
1 arquivos alterados com 11 adições e 1 exclusões
  1. 11 1
      cfc-frontend/pages/profile/service-role-apply.vue

+ 11 - 1
cfc-frontend/pages/profile/service-role-apply.vue

@@ -21,7 +21,7 @@
         <button v-if="applyStatus === 'approved'" class="btn-center" @click="goToCenter">
           进入服务商中心
         </button>
-        <button class="btn-back" @click="uni.navigateBack">返回首页</button>
+        <button class="btn-back" @click="goBack">返回首页</button>
       </view>
     </view>
 
@@ -157,6 +157,16 @@ export default {
     this.checkExistingApply()
   },
   methods: {
+    // 模板里不能直接调用 uni.*(渲染时实例上没有 uni,会报
+    // "Property or method uni is not defined"),统一收进方法
+    goBack() {
+      var pages = getCurrentPages()
+      if (pages && pages.length > 1) {
+        uni.navigateBack()
+      } else {
+        uni.switchTab({ url: '/pages/index/index' })
+      }
+    },
     async checkExistingApply() {
       try {
         const res = await getMyServiceRoleApply()