slot英文就是插槽,其实就是一个占位的,
以前我们写一个组件,比如child组件,组件内部代码会默认被清空
比如<child><span>hello</span></child>,在执行的时候会被child组件内的template替换掉,那么如果我想要保留怎么办呢?就可以使用slot,示例代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Slot</title>
<style type="text/css">
.panel{
width: 400px;
border: 1px solid #ccc;
}
.panel>*{
padding: 15px;
border-bottom: 1px solid #ccc;
}
.footer{
border: none;
}
</style>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/vue@2.6.1-dev.js"></script>
</head>
<body>
<div id="app">
<Child>
<template slot="header" ><div>这是头部</div></template>
<template slot="content" slot-scope="msg"><div>{{msg.data}}</div></template>
<template slot="fooer" ><div>这是尾部</div></template>
</Child>
</div>
<template id="child">
<div>
<div class="panel">
<slot name="header" :data="msg"></slot>
<div class="content">
<slot name="content" :data="msg"></slot>
</div>
<slot name="fooer" :data="msg"></slot>
</div>
</div>
</template>
</body>
<script type="text/javascript">
new Vue({
el:"#app",
data:{
},
components:{
Child:{
template:"#child",
data(){
return{
msg:"这是内容"
}
}
}
}
})
</script>
</html>
网友回复
js如何流式输出ai的回答并折叠代码块,点击代码块右侧可预览代码?
ai大模型如何将文章转换成可视化一目了然的图片流程图图表?
大模型生成html版本的ui原型图和ppt演示文档的系统提示词怎么写?
rtsp视频直播流如何转换成websocket流在h5页面上观看?
为啥coze会开源工作流agent coze studio?
如何检测网页是通过收藏夹打开的?
python如何实现类似php的http动态脚本请求处理响应代码?
js如何实现类似php的http动态脚本请求处理响应代码?
trae与solo有啥区别不同?
vue如何让ai动态生成问卷调查多步骤表单式收集基础信息自动规划执行任务?