Browse Source

fix: 修复picker组件自定义数据默认值问题

songchenglin3 5 years ago
parent
commit
e739c41974
1 changed files with 11 additions and 1 deletions
  1. 11 1
      src/packages/picker/picker-slot.vue

+ 11 - 1
src/packages/picker/picker-slot.vue

@@ -155,7 +155,17 @@ export default {
 
     modifyStatus(type, defaultValue) {
       defaultValue = defaultValue ? defaultValue : this.defaultValue;
-      let index = this.listData.indexOf(defaultValue);
+      let index = -1;
+      if (defaultValue && defaultValue.value) {
+        this.listData.some((item, idx) => {
+          if (item.value == defaultValue.value) {
+            index = idx;
+            return true;
+          }
+        });
+      } else {
+        index = this.listData.indexOf(defaultValue);
+      }
       this.currIndex = index === -1 ? 1 : index + 1;
       let move = index === -1 ? 0 : index * this.lineSpacing;
       type && this.setChooseValue(-move);