Przeglądaj źródła

rename track-by -> key

Evan You 10 lat temu
rodzic
commit
48a0d29e35

+ 1 - 1
src/compiler/parser/index.js

@@ -244,7 +244,7 @@ function processFor (el) {
     } else {
       el.alias = alias
     }
-    if ((exp = getAndRemoveAttr(el, 'track-by'))) {
+    if ((exp = getBindingAttr(el, 'key'))) {
       el.key = exp
     }
   }

+ 2 - 2
src/core/vdom/patch.js

@@ -224,8 +224,8 @@ export function createPatchFunction (backend) {
           /* istanbul ignore if */
           if (process.env.NODE_ENV !== 'production' && !elmToMove) {
             warn(
-              'It seems there are duplicate track-by keys that is causing an update error. ' +
-              'Make sure each v-for item has a unique track-by key.'
+              'It seems there are duplicate keys that is causing an update error. ' +
+              'Make sure each v-for item has a unique key.'
             )
           }
           patchVnode(elmToMove, newStartVnode, insertedVnodeQueue)

+ 3 - 3
test/unit/features/directives/for.spec.js

@@ -232,7 +232,7 @@ describe('Directive v-for', () => {
     expect(vm.$el.textContent).toBe('123')
   })
 
-  it('without track-by', done => {
+  it('without key', done => {
     const vm = new Vue({
       data: {
         items: [
@@ -253,7 +253,7 @@ describe('Directive v-for', () => {
     }).then(done)
   })
 
-  it('with track-by', done => {
+  it('with key', done => {
     const vm = new Vue({
       data: {
         items: [
@@ -262,7 +262,7 @@ describe('Directive v-for', () => {
           { id: 3, msg: 'c' }
         ]
       },
-      template: '<div><div v-for="item in items" track-by="item.id">{{ item.msg }}</div></div>'
+      template: '<div><div v-for="item in items" :key="item.id">{{ item.msg }}</div></div>'
     }).$mount()
     expect(vm.$el.textContent).toBe('abc')
     const first = vm.$el.children[0]

+ 1 - 1
test/unit/modules/compiler/codegen.spec.js

@@ -40,7 +40,7 @@ describe('codegen', () => {
 
   it('generate v-for directive', () => {
     assertCodegen(
-      '<li v-for="item in items" track-by="item.uid"></li>',
+      '<li v-for="item in items" :key="item.uid"></li>',
       `with(this){return (items)&&_l((items),function(item,$index,$key){return _h(_e('li',{key:item.uid}))})}`
     )
   })

+ 2 - 2
test/unit/modules/compiler/parser.spec.js

@@ -115,8 +115,8 @@ describe('parser', () => {
     expect(liAst.iterator).toBe('index')
   })
 
-  it('v-for directive track-by', () => {
-    const ast = parse('<ul><li v-for="item in items" track-by="item.uid"></li><ul>', baseOptions)
+  it('v-for directive key', () => {
+    const ast = parse('<ul><li v-for="item in items" :key="item.uid"></li><ul>', baseOptions)
     const liAst = ast.children[0]
     expect(liAst.for).toBe('items')
     expect(liAst.alias).toBe('item')