1 Star 0 Fork 0

prcool/前端开发学习

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
组件7-插槽.html 1.83 KB
一键复制 编辑 原始数据 按行查看 历史
prcool 提交于 2021-09-11 21:02 +08:00 . 前端开发学习
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<!-- 引入vue.js -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<com1>
插槽内容可以为任何代码,甚至可以是其他组件,但是必须要有slot标签,
如果没有,那么该组件起始标签和结束标签之间的任何内容都会被抛弃。
<h1>我也想进入插槽</h1>
<h2>只能访问父组件的变量:{{msg}}</h2>
<!--无法访问变量url<h2>{{url}}</h2>-->
<p>----------------------------</p>
<com2></com2>
</com1>
</div>
<template id = "temp1">
<div>
<h1>子组件: {{m}}</h1>
<button >子组件按钮</button>
<slot></slot>
</div>
</template>
<template id = "temp2">
<div>
<h1>子组件: {{m}}</h1>
</div>
</template>
</body>
<script>
const com1 ={
template: '#temp1',
data(){
return{
m:'我是子组件的值',
url:'123'
}
}
}
const com2 ={
template: '#temp2',
data(){
return{
m:'我是子组件com2'
}
}
}
// 实例化vue对象
let vm = new Vue({
// 绑定对象
el:'#app',
data:{
msg:'我是父组件的值'
},
methods:{
},
components:{
com1,com2
}
})
</script>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/prcool/front-end-development-learning.git
git@gitee.com:prcool/front-end-development-learning.git
prcool
front-end-development-learning
前端开发学习
master

搜索帮助