Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
haizhilin2013 opened this issue Jun 22, 2019 · 3 comments
Labels
vue vue

Comments

@haizhilin2013
Copy link
Collaborator

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

@haizhilin2013 haizhilin2013 added the vue vue label Jun 22, 2019
@April-Zheng
Copy link

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

@webread
Copy link

webread commented Jul 17, 2019

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

@haungxv
Copy link

haungxv commented Aug 12, 2019

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
Labels
vue vue
Projects
None yet
Development

No branches or pull requests

4 participants