简体   繁体   English

应用 v-for 后的 Vuejs 列表渲染

[英]Vuejs list rendering after applying v-for

i have this kind html in my vue template: it is a simple list rendering我的 vue 模板中有这种 html:它是一个简单的列表渲染

<div class="col-sm-6 col-md-4 col-lg-3" v-for="(lesson) in lessons" :key="lesson.id">
                        <div class="card card--elevated card-course overlay js-overlay mdk-reveal js-mdk-reveal "
                            data-partial-height="40" data-toggle="popover" data-trigger="click">

                            <a href="course.html" class="js-image" data-position="left">
                                <img :src="lesson.cover_image" alt="course">
                                <span class="overlay__content">
                                    <span class="overlay__action d-flex flex-column text-center">
                                        <i class="material-icons">play_circle_outline</i>
                                        <small>Preview course</small>
                                    </span>
                                </span>
                            </a>
                        </div>
                    </div>

the data-partial-height="40", data-toggle="popover" and data-trigger="click" was working fine at first. data-partial-height="40"、data-toggle="popover" 和 data-trigger="click" 起初工作正常。 but once i add the v-for="lesson in lessons":key="lesson.id", and successfully generate the loop through the lessons array, all the styling is broken.但是一旦我在课程中添加了 v-for="lesson":key="lesson.id",并通过课程数组成功生成循环,所有的样式都被破坏了。 i try to bind the value of data-partial-height="40", data-toggle="popover" and data-trigger="click" to the data property, but still nothing change.我尝试将 data-partial-height="40"、data-toggle="popover" 和 data-trigger="click" 的值绑定到 data 属性,但仍然没有任何变化。 any solution?任何解决方案?

Could it be that you're putting your v-for in the wrong element?可能是您将v-for放入了错误的元素中吗? Right now you have it in you upper-level container <div class="col-sm-6 col-md-4 col-lg-3>" so, once you have more than one element in your list (say 10) you will end up with 10 <div class="col-sm-6 col-md-4 col-lg-3" containers that judging by the classes it uses most likely will be placed side-by-side.现在你有它在你的上层容器<div class="col-sm-6 col-md-4 col-lg-3>"所以,一旦你的列表中有多个元素(比如 10)你最终将有 10 个<div class="col-sm-6 col-md-4 col-lg-3"容器,根据它最有可能使用的类来判断,这些容器将并排放置。

In the other hand if you place your v-for in your inner container <div class="card card--elevated... then the result for 10 elements will be somethig like:另一方面,如果您将v-for放在内部容器<div class="card card--elevated...那么 10 个元素的结果将类似于:

<div class="col-sm-6 col-md-4 col-lg-3>
    <div class="card card--elevated ...
    <div class="card card--elevated ...
    <div class="card card--elevated ...`
    ...

<div>

I'm just guessing but maybe this points you on the right direction, if you provide a minimal reproduction I'll be happy to help.我只是猜测,但也许这为您指明了正确的方向,如果您提供最小的复制品,我将很乐意提供帮助。

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

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