【发布时间】: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