在这一步中,你将修复 vue-router 3.1.3 代码中的问题,即在使用 v-slot API 创建路由链接组件并提供多个子元素时,组件渲染会失败。
打开 vue-router-3.1.3/src/components/link.js 文件。
找到以下代码块:
if (scopedSlot) {
if (scopedSlot.length === 1) {
return scopedSlot[0];
} else if (scopedSlot.length > 1 || !scopedSlot.length) {
if (process.env.NODE_ENV !== "production") {
warn(
false,
`RouterLink with to="${this.props.to}" is trying to use a scoped slot but it didn't provide exactly one child.`
);
}
return scopedSlot.length === 0 ? h() : h("span", {}, scopedSlot);
}
}
将代码更新如下:
if (scopedSlot) {
if (scopedSlot.length === 1) {
return scopedSlot[0];
} else if (scopedSlot.length > 1 || !scopedSlot.length) {
if (process.env.NODE_ENV !== "production") {
warn(
false,
`RouterLink with to="${this.to}" is trying to use a scoped slot but it didn't provide exactly one child.`
);
}
return scopedSlot.length === 0 ? h() : h("span", {}, scopedSlot);
}
}
We use cookies for a number of reasons, such as keeping the website reliable and secure, to improve your experience on our website and to see how you interact with it. By accepting, you agree to our use of such cookies. Privacy Policy