关于如何判断插槽是否有内容渲染的疑问
Nobody has claimed this yet.
- Dominant language
- Vue
- Stars
- 3.2k
- Forks
- 5k
- Avg merge
- 14d 17h
- Merged PRs (30d)
- 1
Description
如下代码所示,目前 vue 似乎没有提供在组件中用于判断插槽是否存在的方法,而在我自己实现组件库时,发现判断插槽是否存在是非常普遍使用的一个功能,而 vue 只提供了一个 useSlots() 方法,但是实际中有很多不同的情况需要处理,目前我也无法保证方法一定没有问题,只能是遇到一种情况就处理一种情况。无奈最终自己写了一个判断插槽是否存在的方法:https://themusecatcher.github.io/vue-amazing-ui/utils/functions/slots-exist.html
希望能尽快推出一个判断插槽是否存在的 api
子组件 Child.vue:
<div>
<slot name="title">{{ title }}</slot>
</div>
父组件 Parent.vue:
<Child>
<template #title></template>
</Child>
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing useSlots() against the Child.vue and Parent.vue examples and the linked slots-exist reference. Clarify the supported slot-content cases and acceptance criteria first; done would require an agreed API direction rather than an isolated workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- documentation
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100