Slot_scope 实际上就是用于 将组件内部的slot处的变量 放到了外部的template(div 也可以,大家可以多试几个)中,通过slot-scope进行使用
同一个slot内只能被放置一次

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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="/WEB-INF/webpage/common/taglibs.jspf"%>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>${title}</title>
<meta name="decorator" content="single"/>
<script src="/static/common/js/vue.js"></script>

<link rel="stylesheet" href="https://unpkg.com/iview/dist/styles/iview.css">

<script type="text/javascript" src="/static/common/js/iview.min.js"></script>

</head>
<body>
<div id="app">
<template1 >
<template slot-scope="obj" slot="slot1">
<i-button type="success">{{obj.msg}}-{{name}}</i-button>
</template>
<template slot-scope="obj" slot="slot2">
<div>
<i-button type="success">{{obj.msg}}-{{name}}</i-button>
</div>
</template>
</template1>
<template2>
<template slot-scope="obj" >
<div class="info">
<p>姓名:{{obj.row.name}}-{{name}}</p>
<p>年龄: {{obj.row.age}}-{{name}}</p>
<p>性别: {{obj.row.sex}}-{{name}}</p>
<p>索引:{{obj.index}}-{{name}}</p>
<alert>分割线</alert>
</div><hr>
</template>
</template2>
<i-button @click="counter">counter</i-button>
</div>

<template id="template1">
<div>
<slot name="slot1" msg="msg1111"></slot>
<slot name="slot2" :msg="msg"></slot>
</div>
</template>

<template2 id="template2">
<ul>
<li v-for="(item, index) in data">
<slot :row="item" :index="index"></slot>
</li>
</ul>
</template2>


<script>

Vue.component("template1",{
template:"#template1",
data:function(){
return {
msg:"hello slot scope",
}
},
methods:{

}
})

Vue.component("template2",{
template:"#template2",
data:function(){
return {

data:[
{
name: 'kongzhi1',
age: '29',
sex: 'man'
},
{
name: 'kongzhi2',
age: '30',
sex: 'woman'
}
]
}
},
methods:{

}
})

var app=new Vue({
el:"#app",
data:{
active:"active",
str:null,
input_value:1,
name:1,
},
methods:{
counter:function(){
this.name++;
},
add:function(){
this.$refs.name.style.backGroundColor="red";
this.$refs.name.value=(++this.input_value);
},
btnClick:function(){
this.$refs.div.click();
},
divClick:function(){
alert("div click method")
}
},
computed:{

}
})
</script>
</body>

</html>