【问题标题】:Cannot destructure property 'isActive' of 'undefined' as it is undefined无法解构 \'undefined\' 的属性 \'isActive\' 因为它是未定义的
【发布时间】:2022-11-29 12:38:37
【问题描述】:

在 vue3 中使用脚本设置,我在模板中有这样的代码

   ...
          <router-link
            v-for="t in tas"
            :key="t.text"
            custom
            :to="`/dashboard/${t.type}`"
            v-slot="{ isActive, navigate }"
          >
            <div
              :class="{ active: isActive }"
              @click="navigate"
            >
              {{ t.text }}
            </div>
          </router-link>
   ...

运行简单测试时抛出错误TypeError: Cannot destructure property 'isActive' of 'undefined' as it is undefined.

  it('match snapshot', () => {
    const wrapper = shallowMount(MYView, {
      stubs: ['router-link'],
    });
    expect(wrapper.html()).toMatchSnapshot();
  });

【问题讨论】:

    标签: vuejs3 vue-router


    【解决方案1】:

    您需要使用 RouterLinkStub 存根,请参阅https://test-utils.vuejs.org/api/#routerlinkstub

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-08
      • 2020-10-07
      • 1970-01-01
      • 2021-03-08
      • 2021-05-11
      • 2021-04-04
      • 2021-08-30
      • 1970-01-01
      相关资源
      最近更新 更多