Prechádzať zdrojové kódy

fix(cf-web): 修复套餐子商品添加按钮 TypeError(this 为 null)

@click="addBundleItem" 这类裸方法引用会被编译成 on:{click:_vm.method},
Vue updateListeners 用 createFnInvoker 包装后以 context=null 调用
(invokeWithErrorHandling(fns, null, ...) -> handler.apply(null, args)),
ESM 严格模式下 this 保持 null,点击时读取 this.bundleItems 抛
TypeError: Cannot read properties of null。

改为内联调用 @click="method()",编译器生成 function($event){return method()},
表达式处于 render 的 with(this) 作用域内,标识符解析为 vm 上的方法,this 正确绑定。

同文件另 3 处同模式裸绑定(addSelectedGuide/addOnlineSlot/handleSave)一并修复。
Xiaogang Liao 1 týždeň pred
rodič
commit
6de93adbe3
1 zmenil súbory, kde vykonal 4 pridanie a 4 odobranie
  1. 4 4
      cfc-web/src/views/admin/ProductEdit.vue

+ 4 - 4
cfc-web/src/views/admin/ProductEdit.vue

@@ -77,7 +77,7 @@
               <el-input-number v-model="item.quantity" :min="1" :precision="0" size="small" style="width:110px;" />
               <el-button type="danger" size="mini" @click="removeBundleItem(idx)">删除</el-button>
             </div>
-            <el-button type="primary" size="mini" plain @click="addBundleItem">+ 添加子商品</el-button>
+            <el-button type="primary" size="mini" plain @click="addBundleItem()">+ 添加子商品</el-button>
             <div style="margin-top:8px; font-size:12px; color:#999;">套餐出库时自动完成所有组成商品出库(数量 × 套餐数量)</div>
           </el-form-item>
         </template>
@@ -209,7 +209,7 @@
                   <span style="float:right;color:#999;font-size:12px">{{ g.title || g.specialty || '' }}</span>
                 </el-option>
               </el-select>
-              <el-button type="primary" size="mini" style="margin-left:8px" @click="addSelectedGuide">添加</el-button>
+              <el-button type="primary" size="mini" style="margin-left:8px" @click="addSelectedGuide()">添加</el-button>
               <div class="delivery-config-hint" style="margin-top:4px">时段由服务商在「服务商管理」中统一配置</div>
             </div>
             <!-- 已选服务者列表 -->
@@ -248,7 +248,7 @@
               <el-input v-model.number="slot.maxCapacity" placeholder="容量" style="width: 90px; margin-left: 8px" />
               <el-button type="text" size="mini" @click="removeOnlineSlot(idx)">删除</el-button>
             </div>
-            <el-button type="primary" plain size="mini" @click="addOnlineSlot">+ 添加时段</el-button>
+            <el-button type="primary" plain size="mini" @click="addOnlineSlot()">+ 添加时段</el-button>
           </div>
         </el-form-item>
 
@@ -341,7 +341,7 @@
         </el-form-item>
 
         <el-form-item>
-          <el-button type="primary" :loading="saving" @click="handleSave">
+          <el-button type="primary" :loading="saving" @click="handleSave()">
 {{ isEdit ? '保存修改' : '创建商品' }}
           </el-button>
           <el-button @click="$router.back()">取消</el-button>