Skip to content
New issue

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

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

Already on GitHub? # to your account

01.GettingStarted-simple-demo.html中的问题 #17

Open
zhaozhenyi opened this issue Mar 19, 2017 · 4 comments
Open

01.GettingStarted-simple-demo.html中的问题 #17

zhaozhenyi opened this issue Mar 19, 2017 · 4 comments

Comments

@zhaozhenyi
Copy link

v-for="(person, index) in people"
这个应该为
v-for="(index,person) in people"
吧。
索引在前,元素在后。

@wangmaojiawan
Copy link

这个不一定的吧?你看jquery里面function里面2种都是有的啊。

@HeZhaoyin
Copy link

@wangmaojiawan 这个还真的就是一定的,但是(index,person) in people这种索引在前,元素在后是vue1.x的写法。到了vue2.0,就换成了(person,index) in people这种元素在前,索引在后的写法了。
现在如果你使用vue2.0,还是索引在前元素在后,会出错
详见Vue官方文档(从Vue1.x迁移):
http://cn.vuejs.org/v2/guide/migration.html#v-for-遍历数组时的参数顺序-变更

@HeZhaoyin
Copy link

@wangmaojiawan 对了.. 也顺便说一下,其实官方文档里面也有写,Vue2.0之所以这么改,是因为想跟原生JS的forEach方法保持一致(元素在前,索引在后)

@wangmaojiawan
Copy link

@BunnyWithYou 但是现在用原生都JS的forEach方法都少了,一般都会用jQuery的Each方法了吧,我还觉得保持和jQuery的一致好一些。

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants