-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
使用slot做切换卡.html
68 lines (64 loc) · 2.23 KB
/
使用slot做切换卡.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<html>
<head>切换卡</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src='../../dist/avalon.js'></script>
<script>
function heredoc(fn) {
return fn.toString().replace(/^[^\/]+\/\*!?\s?/, '').
replace(/\*\/[^\/]+$/, '').trim().replace(/>\s*</g, '><')
}
avalon.component('ms-tabs', {
template: heredoc(function () {
/*
<div>
<div><slot name="btn"/></div>
<div><slot name="tab"/></div>
</div>
*/
}),
defaults: {
buttons: [],
tabs: [],
active: function (index) {
this.activeIndex = index
},
activeIndex: 0,
}
})
var vm = avalon.define({
$id: 'widget1',
buttons: [111, 222, 333],
aa: '动态内容',
ddd: function () {
console.log('xxxx')
},
change: function () {
vm.aa = '更新内容'+(new Date -0)
}
})
</script>
</head>
<body>
<h1>slot的使用</h1>
<div ms-controller='widget1' >
<xmp :widget="{is:'ms-tabs',buttons: @buttons}">
<button ms-for='(index,button) in @buttons'
ms-click='@active(index)'
type='button'
slot='btn'
>{{button}}</button>
<div slot="tab" ms-visible="0 == @activeIndex">
<p>这是面板1</p>
</div>
<div slot="tab" ms-visible="1 == @activeIndex">
{{@aa}} <button ms-click="@change" type="button">change</button>
</div>
<div slot="tab" ms-visible="2 == @activeIndex">
这是面板3
</div>
</xmp>
</div>
</body>
</html>