Browse Source

test(tabs): add error tips

richard1015 3 years ago
parent
commit
b889450e19

+ 1 - 1
src/packages/__VUE/tabs/__tests__/index.spec.ts

@@ -23,7 +23,7 @@ test('base Tabs', () => {
 test('base tabs props', async () => {
   const wrapper = mount(Tabs, {
     props: {
-      'v-model': 0,
+      modelValue: '0',
       background: '#f5f5f5',
       color: '#f5f5f5',
       direction: 'horizontal',

+ 3 - 1
src/packages/__VUE/tabs/common.ts

@@ -82,7 +82,9 @@ export const component = {
     const currentIndex = ref((props.modelValue as number) || 0);
     const findTabsIndex = (value: string | number) => {
       let index = titles.value.findIndex((item) => item.paneKey == value);
-      if (index == -1) {
+      if (titles.value.length == 0) {
+        console.error('[NutUI] <Tabs> 当前未找到 TabPane 组件元素 , 请检查 .');
+      } else if (index == -1) {
         console.error('[NutUI] <Tabs> 请检查 v-model 值是否为 paneKey ,如 paneKey 未设置,请采用下标控制 .');
       } else {
         currentIndex.value = index;