Vuejs slot插槽(显示子组件标签下的内容)

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<meta http-equiv="X-UA-Compatible" content="ie=edge">

<script src="https://unpkg.com/vue/dist/vue.js"></script>

<title>Document</title>

</head>

<body>

<div id = "myApp">

<sayto pname = "koma">我是koma</sayto>

<sayto pname = "haohao">我是haohao</sayto>

<sayto pname = "vue">我是vue</sayto>

</div>

<script>

Vue.component('sayto',{

props:['pname'],

template:'<div>'

+ 'nihao,<strong>{{pname}}</strong>!'

+ '<slot></slot>'

+ '</div>',

});

var myApp = new Vue({

el:"#myApp",

});

</script>

</body>

</html>

猜你喜欢

转载自blog.csdn.net/xlh006/article/details/83659862