Skip to content

[vue] vue使用v-for遍历对象时,是按什么顺序遍历的?如何保证顺序? #463

Open
@haizhilin2013

Description

@haizhilin2013
Collaborator

[vue] vue使用v-for遍历对象时,是按什么顺序遍历的?如何保证顺序?

Activity

April-Zheng

April-Zheng commented on Jul 1, 2019

@April-Zheng

在遍历对象时,会按 Object.keys() 的结果遍历,但是不能保证它的结果在不同的 JavaScript 引擎下都一致。

webread

webread commented on Jul 17, 2019

@webread

---值value---{{v}}---键key---{{k}}----索引index----{{i}}

haungxv

haungxv commented on Aug 12, 2019

@haungxv

image
1、会先判断是否有iterator接口,如果有循环执行next()方法
2、没有iterator的情况下,会调用Object.keys()方法,在不同浏览器中,JS引擎不能保证输出顺序一致
3、保证对象的输出顺序可以把对象放在数组中,作为数组的元素

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @haizhilin2013@April-Zheng@webread@haungxv

        Issue actions

          [vue] vue使用v-for遍历对象时,是按什么顺序遍历的?如何保证顺序? · Issue #463 · haizlin/fe-interview