Home > Article > Web Front-end > The div in the vue component cannot be displayed
When we use the Let’s analyze possible causes and solutions step by step: Vue components are componentized through templates. Developed, they are classified into three types: Vue’s component rendering mechanism requires that each Vue component must be like an independent and complete Page, that is, each Vue component must have one and only one root element. Therefore, some irregular writing methods may cause the component to fail to render. If only the Solution: Add some content or set related styles to make it display. When we add multiple root elements to the Vue component, as shown below: 这是内容 At this time we found that the The component will not be rendered and no error will be reported. This is because Vue stipulates that each component can only have one root element. Solution: Change it to a form with only one root element, as shown below: 这是内容 When we use For example: In the above code, because of the expressions of Solution: You can change the expression bound to this directive to When we use the slot in the Vue component, the For example: In the above code, since no content or style is added to the The above is the detailed content of The div in the vue component cannot be displayed. For more information, please follow other related articles on the PHP Chinese website!1. Vue component rendering mechanism
2. Frequently Asked Questions
2.1 The Vue component does not add content
2.2 The root element in the Vue component can only be one
这是标题
这是标题
2.3 V-show, v-if and other instructions are used in the Vue component
v-show
, v-if
and other instructions in the Vue component, because of Vue’s component rendering mechanism, if the expression bound to the instruction is false
, the element will not be rendered.
v-show="false"
and v-if="false"
Both are false
, so these two true
, or add the content or style of the element so that it can be rendered. 2.4 The slot is used in the Vue component
tag to make it display, as shown below:
3. SummaryThe problem of using tags in Vue components cannot be rendered, usually due to the Vue component rendering mechanism, multiple root nodes, and instruction binding expressions being
false Or it is caused by reasons such as no content being added to the slot. We can easily solve this problem by adding some content or styling.