mirror of https://github.com/vuejs/vue.git
feat($compiler): supports compiling v-for to the weex native directive
This commit is contained in:
parent
7ad368ebb6
commit
9bd1483803
|
|
@ -3,6 +3,7 @@
|
|||
import { transformText } from './text'
|
||||
import { transformVBind } from './v-bind'
|
||||
import { transformVIf } from './v-if'
|
||||
import { transformVFor } from './v-for'
|
||||
|
||||
let currentRecycleList = null
|
||||
|
||||
|
|
@ -16,6 +17,7 @@ function transformNode (el: ASTElement) {
|
|||
if (currentRecycleList) {
|
||||
// TODO
|
||||
transformVIf(el)
|
||||
transformVFor(el)
|
||||
transformVBind(el)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
/* @flow */
|
||||
|
||||
import { addAttr } from 'compiler/helpers'
|
||||
|
||||
function isVForAttr (name: string): boolean {
|
||||
return /^v\-for/.test(name)
|
||||
}
|
||||
|
||||
export function transformVFor (el: ASTElement) {
|
||||
for (const attr in el.attrsMap) {
|
||||
if (!isVForAttr(attr)) {
|
||||
continue
|
||||
}
|
||||
const desc: Object = {
|
||||
'@expression': el.for,
|
||||
'@alias': el.alias
|
||||
}
|
||||
if (el.iterator1) {
|
||||
desc['@index'] = el.iterator1
|
||||
}
|
||||
if (el.iterator2) {
|
||||
desc['@key'] = el.iterator1
|
||||
desc['@index'] = el.iterator2
|
||||
}
|
||||
addAttr(el, '[[repeat]]', desc)
|
||||
el.attrsMap['[[repeat]]'] = desc
|
||||
el.attrsList.push({ name: '[[repeat]]', value: desc })
|
||||
delete el.attrsMap[attr]
|
||||
delete el.for
|
||||
delete el.alias
|
||||
delete el.key
|
||||
delete el.iterator1
|
||||
delete el.iterator2
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue