【问题标题】:How can i 'v-repeat' through this object?我怎样才能通过这个对象“重复”?
【发布时间】:2023-04-05 17:44:02
【问题描述】:

当我使用“v-repeat”时,我可以看到“post.letter”,但看起来我还需要在同一个“v-repeat”中循环遍历帖子数组?

当我尝试“post.posts.title”时,我什么也得不到,当我执行“post.posts”时,我得到 [object, object]。

        var myObj = [
        {
            post: {
                letter: 'A',
                posts: [
                    { title: 'lorem ipsum'},
                    { title: 'dolor sit amet'}
                ],
            }
        }
    ];

【问题讨论】:

  • v-repeat 是 VueJs 指令。
  • posts 是一个数组,你很可能想要post.posts[0].titlepost.posts[1].title

标签: javascript arrays object vue.js


【解决方案1】:

如果我正确理解您想要的内容,您可以使用别名

<h4>{{ post.letter }}</h4>
<ul>
    <li v-repeat="subPost : post.posts"> {{ subPost.title }}</li>
</ul>

希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 2017-06-02
    • 2012-11-27
    • 1970-01-01
    • 2014-08-11
    • 1970-01-01
    • 2021-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多