solution
When using 自定义组件
or slot标签
as 组件A
the content of a slot, 组件A
a default slot must be defined in , and there are no restrictions on tags such as ordinary views. And since the slot equivalent wx:if
for false
is not defined
Scenario recurrence (just take the situation I encountered as an example)
1. Debug the basic library 2.19.4
2. Use the component package of weapp, take van-search
the components in it as an example
3. When used in any page van-search
, the warning will appear in the console [Component] slot "" is not found.
, which does not affect the running of the program, but just looks uncomfortable
Troubleshooting process
According to the literal meaning of the error, an undefined default slot is used.
Let’s look at the normal default slot use cases.
Examples include: custom componentscustom
//自定义组件 custom
<view>
<slot></slot>
</view>
home
Used in another component|pagecustom
// home
<custom>
<view>22</view>
</custom>
The above usage is to use the default slot, and the console will not have any warning, even if the custom
slot in is removed, there will be no warning, but when a custom component or a slot label is used as the content of the slot, and there custom
is no [Component] slot "" is not found.
A warning will appear for the default slot .
Take van-search
as an example, van-search
there is such a structure in ,
here are two slots as van-filed
the content of the slot, enter and van-filed
you will find that there is no default slot defined, at this time, van-field
add a default slot at any position, and the console will not appear after refreshing The previous warning message will appear
Take van-popup
another example, although there is a default slot, but because the initial value of wx:if is false, the initial parsing is skipped
Notice
Adding a slot that does not affect the display is not the best way, just to avoid warning messages
Replenish
Although the setting display:none
can not display the useless default slot, it may eventually load this piece of useless content, which can be considered for joint use wx:if=“visible”
, but visible
the default value is true
, through the timer or other timing after loading, it will visible
becomefalse
However, this method will introduce another problem
[Component] slot "" duplication is found under a single shadow root. The first one was accepted
Literally, there are two slots, the first one is used, the main code is as follows
It is found that we added to avoid the problem of the code block that the slot is not found abnormally, because when the pop-up window is displayed, the upper and lower slots can be parsed, so give us a hint to tell us, bold 有两个slot,程序不知道要显示那个,因此就给你显示了第一个
guess , if the first slot is inappropriate during the code parsing process, but there is a suitable slot later, this prompt will not be given, modify as follows and the
warning will disappear
reference
Analytical descriptions from other bloggers
Summarize
In the final analysis, this is a problem with development tools. Of course, it is understandable to give such warnings. Although it can be solved by hacking, it is not the best way.