效果:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>
<body>
<div id="app">
<cpn></cpn>
<cpn>
<!-- slot-scope="slot"固定写法,slot可以随便定义,后面必须要跟组件定义的 -->
<template slot-scope="slot">
<!-- 拿到数据后可以自己随意修改想显示的排版 -->
<ul>
<li v-for="item in slot.data">{{item}}</li>
</ul>
</template>
</cpn>
</div>
<template id="cpn">
<div>
<!-- data这个属性可以随便定义 -->
<slot :data="pLanauage">
<span v-for="item in pLanauage">---{{item}}---</span>
</slot>
</div>
</template>
</body>
<script type = "text/javascript">
var vm = new Vue({
el:"#app",
data:{
},
components:{
cpn:{
template:'#cpn',
data(){
return {
pLanauage: ['java', 'javascript', 'go', 'c++', 'oc']
}
},
methods:{
}
}
},
methods:{
}
});
</script>
</html>
记录一下 避免忘记!!!