vue插槽

<!DOCTYPE html>
<html>
<head>
	<title>vue插槽</title>
	<script type="text/javascript" src="vue.js"></script>
</head>
<body>
	<div id="app">
		<child>
			{% comment %} 此时里面的内容都传入slot-scope {% endcomment %}
			<template slot-scope="props">
					<li>{{props.item}}</li>
			</template>
			<slot></slot>
		</child>
		<slot></slot>
	</div>
</body>
<script type="text/javascript">

	Vue.component('child',{
		data:function(){
			return{
				list:[1,2,3,4]
			}
		},
		template:'<div><slot v-for="item of list" :item=item></slot></div>'
	})
	vm  = new Vue({
		el:'#app',
		data:{

		}
	})

</script>
</html>

在子组件的插槽定义,使用v-bind进行绑定传值,并且对于插槽的传值使用如下方式,必须是template标签

	<template slot-scope="props">
					<li>{{props.item}}</li>
	</template>
			<template slot="girl">
					那颗
			</template>
			
		</child>

<script type="text/javascript">
	Vue.component('child',{
		template:'<div><h4><slot name="girl"></slot></h4><h1><slot name="python">技术</slot></h1></div>'
	})

这种方式也能实现插槽的效果,在子组件定义这个名字

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值