<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>作用域插槽</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.js"></script>
</head>
<body>
<div id="root">
<child :info="userInfo">
<li slot-scope="props">
{{props.i}}---{{props.k}}---{{props.v}}
</li>
</child>
</div>
<script>
Vue.component('child', {
props:{
info: Object
},
data(){
return {
list: this.info
}
},
template: `<div>
<ul>
<slot v-for="(v, k, i) of list" :v="v" :k="k" :i="i"></slot>
</ul>
</div>`,
})
var vm = new Vue({
el: '#root',
data:{
userInfo: {
name: 'sinoey',
gender: 'male',
address: 'beijingshi',
tel: 19912345678
}
}
})
</script>
</body>
</html>