<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Vue中的作用域插槽</title>
</head>
<body>
<div id="app">
<child>
<template slot-scope="props">
<h2>{{props.item}}</h2>
</template>
</child>
</div>
<!-- 开发环境版本,包含了用帮助的命令行警告 -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script type="text/javascript">
Vue.component('child', {
data: function() {
return {
list: [1,2,3,4,5]
}
},
template: `<div>
<ul>
<slot v-for="item of list"
:item = item>
{{item}}
</slot>
</ul>
</div>`
})
var app = new Vue({
el: '#app'
})
</script>
</body>
</html>
Vue中的作用域插槽的相关教程结束。