web前端|js教程
使用方法,通信,组件
web前端-js教程
jsp图片网站源码,冷门vscode插件,qt4.8.7安装ubuntu,tomcat-8.0.53,sqlite 隔n行,简单的js音频播放插件,前端react框架的前景,爬虫逆向是啥,php 正则 提取,手机网站seo软件,网站过期提醒源码下载,网页头部有空白,opensns商城模板,js怎么把html页面当作对话框弹出,小说网站后台管理系统,人人商城小程序手动上传教程lzw
这次给大家带来vue父子组件通信使用方法,使用vue父子组件通信的注意事项有哪些,下面就是实战案例,一起来看一下。
android 小视频源码下载,vscode插件更新原理,ubuntu如何连接,怎么知道启动tomcat,粪便爬虫,php百分号,惠州seo排名怎么收费,单页式网站系统,本地网址模板修改lzw
{{msg}}
免费开源商城系统源码排行,vscode调试js解密,ubuntu 手机系统,使用自己的tomcat,邮件爬虫,php 验证码复杂,seo站内优化在线咨询,教学视频网站模版,考试答题html模板lzw
// 创建父组件 ponent("chat-room",{ //data属性中的chatList保存用户聊天信息 data:function(){ return{chatList:[] } }, template:`
//假的聊天室
假的聊天室
//显示用户的聊天信息{{tmp}} ` }) //创建子组件 ponent("user-component",{ props:["userName"], //通过v-model把用户输入的数据保存到userInput数组 data:function(){ return {userInput:[] } }, methods:{ //把用户输入的数据以及用户名label信息push给chatList数组 sendChat:function(){this.$parent.chatList.push(this.userName+":"+this.userInput);//情况input框this.userInput =" "; } }, template:`
` }) new Vue({ el:"#container", data:{ msg:"Hello VueJs" } })
组件间通信综合练习:
(props down,events up)
有2个组件:chat-room,user-component
user-component是由label input button构成
chat-room是由两个user-component和一个列表构成
①在chat-room调用user-component指定label的名字
②在user-component,
点击按钮时,将当前用户输入的信息发送给chat-room组件,chat-room接收到数据显示在列表中
代码:
ponent(chat-room,{ methods:{ recvMsg:function(msg){ console.log("在父组件中接收子组件传来的数据"+msg); this.chatList.push(msg); } }, data: function () { return { chatList:[] } }, template:`
假的聊天室
{{tmp}} ` }) ponent(user-component,{ props:[userName], data: function () { return { userInput:\ } }, methods:{ sendToFather: function () { //触发toFatherEvent的事件,把input中 //用户输入的数据发送 this.$emit("sendToFather",this.userName+":"+this.userInput); } }, template:`
` }) new Vue({ el: #container, data: { msg: Hello Vue } })