vue-vben-admin
vue-vben-admin copied to clipboard
fix: 删除无用代码,$slots中已包含
General
✏️ Mark the necessary items without changing the structure of the PR template.
- [ ] Pull request template structure not broken
Type
ℹ️ What types of changes does your code introduce?
👉 Put an
xin the boxes that apply
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update
Checklist
ℹ️ Check all checkboxes - this will indicate that you have done everything in accordance with the rules in CONTRIBUTING.
👉 Put an
xin the boxes that apply.
- [x] My code follows the style guidelines of this project
- [x] Is the code format correct
- [x] Is the git submission information standard?
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my feature works
- [x] New and existing unit tests pass locally with my changes
- [x] Any dependent changes have been merged and published in downstream modules
很抱歉,上次的pr#1991我没有注意到;在BasicTable.vue的写的bodyCell slot其实只是一个默认的情况,最终是会被$slots的循环给替换。所以上次#1991增加bodyCell slot是很多余的。
很抱歉,上次的pr#1991我没有注意到;在BasicTable.vue的写的bodyCell slot其实只是一个默认的情况,最终是会被$slots的循环给替换。所以上次#1991增加bodyCell slot是很多余的。
你好,我想请教一下我们如果写两个同名template #badycell 回报Duplicate slot names found. 而循环slot出的反而可以做到覆盖呢
很抱歉,上次的pr#1991我没有注意到;在BasicTable.vue的写的bodyCell slot其实只是一个默认的情况,最终是会被$slots的循环给替换。所以上次#1991增加bodyCell slot是很多余的。
你好,我想请教一下我们如果写两个同名template #badycell 回报Duplicate slot names found. 而循环slot出的反而可以做到覆盖呢
这个得看template解析的代码是怎么样的,访问下面的链接,然后点击js部分查看编译后的代码。
写了一个demo
其实啊,你说的报错,我认为是语法检查的错误;如果你其中一个template的名字是使用动态的话,比如一个变量,那么就不会检测到。
再者就是$slots是一个对象,所以说按照上面的写法,绕过了检查,但因为key相同,最终是出现了覆盖。那从上面的demo地址可以看到最后的编译代码,vfor的层级是最高的,最终是使用了循环的slot渲染
贴一下$slots源码
// instance.ts
// overrides existing accessor
$slots: i => {
if (
isCompatEnabled(DeprecationTypes.RENDER_FUNCTION, i) &&
i.render &&
i.render._compatWrapped
) {
return new Proxy(i.slots, legacySlotProxyHandlers)
}
return __DEV__ ? shallowReadonly(i.slots) : i.slots
},
// componentFunctional.ts
export const legacySlotProxyHandlers: ProxyHandler<InternalSlots> = {
get(target, key: string) {
const slot = target[key]
return slot && slot()
}
}