vue实现组件之间传值功能示例
网络编程 2021-07-04 16:46www.168986.cn编程入门
这篇文章主要介绍了vue实现组件之间传值功能,结合实例形式分析了vue.js父子组件之间相互传值常见操作技巧,需要的朋友可以参考下
本文实例讲述了vue实现组件之间传值功能。分享给大家供大家参考,具体如下:
slot标签:
想向封装好结构的组件中插入内容,需要借助<slot></slot>
在组件之中进行关联:如
模板中:
<slot name='txt'></slot>
组件调用中:
<p slot='txt'></p>
注:如果只有slot上面每一定义name属性,则只能有一个slot
<div class='box'> <> <p slot='txt'></p> </> </div> <template id="c"> <div> <slot name="txt"></slot> </div> </template>
Vue.ponent('',{ template:"#c" })
父组件向子组件传值:props
父组件:
<template> <child :parent-msg='a'></child> </template>
子组件:
child:{ template:'#chi' props:['parentMsg'] }
子组件向父组件的传值:
vue只运行数据的单选传递,在子组件向父组件的传值中,需要事件触发
子组件:
<template> <div @click="up"></div> </template>
methods:{ up(){ this.$emit('fn','msg') // 主动触发fn方法,msg是需要传递的数据 } }
父组件:
<div> <child @fn="getval"></child> </div>
methods:{ getval(msg){ // msg接收到的数据 this.msg=msg } }
希望本文所述对大家vue.js程序设计有所帮助。
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程