<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>slot内容分发</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<my-hello>
<ul slot="s2">
<li>aa</li>
<li>bb</li>
<li>cc</li>
</ul>
我是需要额外显示的组件的内容
<ul slot="s1">
<li>1222</li>
<li>1222</li>
<li>1222</li>
</ul>
</my-hello>
</div>
<template id="hello">
<div>
<slot name='s1'>如果没有内容,就显示</slot>
<h3>welcome to itapp</h3>
<slot>如果没有内容,就显示</slot>
<slot name='s2'>如果没有内容,就显示</slot>
</div>
</template>
<script>
var vm=new Vue({
el:'#app',
components:{
'my-hello':{
template:'#hello'
}
}
});
</script>
</body>
</html>
(精华)2020年7月12日 vue slot插槽(内容分发)的使用
原创
©著作权归作者所有:来自51CTO博客作者愚公搬代码的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章