forked from ygs-code/vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparseModifiers.html
38 lines (34 loc) · 1.03 KB
/
parseModifiers.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
var modifierRE = /\.[^.]+/g; // 匹配以点开头的分组 不属于点 data.object.info.age 匹配到 ['.object','.info' , '.age']
function parseModifiers(name) {
// 匹配以点开头的分组 不属于点 data.object.info.age 匹配到 ['.object','.info' , '.age']
var match = name.match(modifierRE);
console.log(match)
if (match) {
var ret = {};
match.forEach(function (m) {
console.log(m)
console.log(m.slice(1))
ret[m.slice(1)] = true;
});
return ret
}
}
let name = 'data.props.name'
let modifiers = parseModifiers(name);
console.log(modifiers)
debugger
if (modifiers) {
name = name.replace(modifierRE, '');
}
console.log(name)
</script>
</body>
</html>