MCPcopy Index your code
hub / github.com/ygs-code/vue / parseFor

Function parseFor

vue.js:13624–13651  ·  view source on GitHub ↗
(exp //字符串 列如 是 (item,index) in data 或 item in data 或item of data 或者(item,index) of data
    )

Source from the content-addressed store, hash-verified

13622
13623 //转换 for指令 获取 for中的key 返回一个res对象为{for:data字符串,alias:value字符串,iterator1:key字符串,iterator2:index字符串}
13624 function parseFor(exp //字符串 列如 是 (item,index) in data 或 item in data 或item of data 或者(item,index) of data
13625 ) {
13626 var inMatch = exp.match(forAliasRE); //匹配 含有 字符串 in 字符串 或者 字符串 of 字符串 比如(value, key, index) in data
13627 if (!inMatch) { //如果匹配不上则返回出去
13628 return
13629 }
13630 var res = {};
13631 console.log(inMatch)
13632
13633 res.for = inMatch[2].trim(); //获取到数据 data 字符串
13634 var alias = inMatch[1].trim().replace(stripParensRE, ''); //去除括号 比如(value, key, index) in data 变成 value, key, index
13635
13636
13637 var iteratorMatch = alias.match(forIteratorRE); // 匹配出分组 [0: ", key, index", 1: " key" , 2: "index"]
13638
13639 if (iteratorMatch) {
13640 res.alias = alias.replace(forIteratorRE, ''); // value , key , index 去掉 ,+字符串 获得value 字符串
13641 console.log(res.alias)
13642
13643 res.iterator1 = iteratorMatch[1].trim(); //获取第二个字符串 key
13644 if (iteratorMatch[2]) {
13645 res.iterator2 = iteratorMatch[2].trim(); //获取第三个字符串 index
13646 }
13647 } else {
13648 res.alias = alias; //单个字符串的时候 value in data
13649 }
13650 return res
13651 }
13652
13653 //获取v-if属性,为el虚拟dom添加 v-if,v-eles,v-else-if 属性
13654 function processIf(el) {

Callers 1

processForFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected