<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<!--
组件插槽的作用
- 父组件向子组件传递内容
-->
<!--
组件插槽的基本用法:
(1)插槽位置
Vue.component('alert-box',{
template:`
<div class="demo-alert-box">
<strong>error!</strong>
<slot></slot>
</div>
`
}
);
(2)插槽内容
<alert-box>Something bad happened.</alert-box>
-->
<div id="app">
<alert-box>有BUG发生!</alert-box>
<alert-box>有一个warnning!</alert-box>
<alert-box></alert-box>
</div>
<script src="./vue/vue.js"></script>
<script>
Vue.component('alert-box',{
template:`
<div>
<strong>ERROR:</strong>
<slot>默认</slot>
</div>`
});
var vm = new Vue({
el:"#app",
data:{},
methods:{}
});
</script>
</body>
</html>
网友评论