简体   繁体   English

条件渲染以在vue中显示组件

[英]conditional rendering to display component in vue

I have a parent comp which content should be displayd conditionally我有一个父组件,其中的内容应该有条件地显示

when the userinput variable is falseuserinput变量为假时
The <div class="parent"> should be removed and the PopUp component displayed应删除<div class="parent">并显示 PopUp 组件


I tried to use `v-if` but dont know how to remove the entire div with it elements 我尝试使用 `v-if` 但不知道如何删除整个 div 元素

I could only change single elements with v-if else我只能用v-if else改变单个元素

parent comp母公司

<template>
    <div>
        <button>x</button>
        <p>errorMessage</p>
    </div>
</template>

child component - PopUp子组件 - PopUp

 <template> <div> <button>x</button> <p>errorMessage</p> </div> </template>

Add v-if="userinput" doesn't work?添加v-if="userinput"不起作用?

If I understand what you want, you should have something like this:如果我明白你想要什么,你应该有这样的东西:

 // parent comp <template> <div> <h1>header</h1> <div v-if="userinput" class="parent"> <h2>infos</h2> <button>x</button> </div> <PopUp v-else/> </div> </template>

Do not hesitate to read the Vue.js documentation不要犹豫,阅读Vue.js 文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM