复盘-----vue---组件传参

定义组件->注册组件->使用组件

eg:监听数值的大小改变圆的大小

<style>
	.cricle{border:1px soild #000;text-align:center;}
</style>
<div id="app">
	//03使用组件
	<steper :num="r" @countchage="r=$event "></steper>
	<div class="cricle" :style="width:r+'px';height:r+'px';borderRadius:r+'px'"></div>
</div>
<script>
    //01定义组件
const steper={
   template:`
	<span>
		<button @click="count--">-</button>
		<input type="text" v-model.number="count" />
		<button @click="count++">+</button>
	</span>
`
	data(){
		return{
			count:this.num
			}
	}
	props:['num'],
	watch:{
		"count":{hanlder(){
			this.$emit("countchange",this.count)//this.$emit("时间名",值)发送一个事件,携带事件值   <steper v-on:"事件名"="$event">
		},deep:true}
}
new Vue({
 el:"#app",
 //02注册组件
 components:{steper},
 data(){
 	return {r:100}
 }
})
</script>

父传子 :num="r"传入 props:[num]接收num

子传父 $emit传出事件携带值 @事件名=" r= $event"接收

$event就是 $emit传出的this.count的值

组件插槽

//组件中eg:
<steper><slot><slot><steper>
<steper><p>东方红啦啦啦</p></steper>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值