页面中没有div b,为什么?

发布于 2025-02-01 08:52:33 字数 959 浏览 0 评论 0原文

<template>
    <div class="test">
        <template v-if="arr && arr.length">
            <div class="a">rendered in dom</div>
            <div class="b">
                <span>not render</span>
                <el-button>but this child component is created, we can see it in vue-devtool</el-button>
            </div>
        </template>
        <div class="c" v-else>test</div>
        <el-dialog append-to-body :modal="false" :visible="visible" @close="visible = false">1</el-dialog>
    </div>
</template>

<script>
export default {
    name: 'HelloWorld',
    data() {
        return {
            arr: [],
            visible: true
        };
    },
    mounted() {
        this.arr = [1, 2];
    }
};
</script>

有很多解决方案,例如: 添加键,更改不同的标签等等,但是为什么呢?

最重要的是,如果删除对话框,它可能会带有期望!

<template>
    <div class="test">
        <template v-if="arr && arr.length">
            <div class="a">rendered in dom</div>
            <div class="b">
                <span>not render</span>
                <el-button>but this child component is created, we can see it in vue-devtool</el-button>
            </div>
        </template>
        <div class="c" v-else>test</div>
        <el-dialog append-to-body :modal="false" :visible="visible" @close="visible = false">1</el-dialog>
    </div>
</template>

<script>
export default {
    name: 'HelloWorld',
    data() {
        return {
            arr: [],
            visible: true
        };
    },
    mounted() {
        this.arr = [1, 2];
    }
};
</script>

There are many solutions for this, e.g:
add key, change a different tag, and so on, but why ?

Most important, if delete the dialog, it could run with expectations!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文