国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

Vue 父子組件、組件間通信

2019-11-19 17:14:26
字體:
來源:轉載
供稿:網友

本人對Vue組件間通信不懂,搜索了很多關于Vue 父子組件間通信介紹,下面我來記錄一下,有需要了解Vue 父子組件、組件間通信的朋友可參考。希望此文章對各位有所幫助。

<!DOCTYPE html><html lang="en"><head>  <meta charset="UTF-8">  <title>組件</title>  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">  <meta name="apple-mobile-web-app-capable" content="yes">  <meta name="apple-mobile-web-app-status-bar-style" content="black">  <script src="../js/Vue.js"></script>  <script>    window.onload = function(){      var vm = new Vue({        el:'#box',        data:{},        components:{          aaa:{            template:'<h2>這是aaa組件<bbb></bbb></h2>',            components:{              bbb:{                template:'<h2>這是bbb組件</h2>'              }            }          }        }      });    }  </script></head><body><div id="box">  <aaa></aaa></div></body></html>
<!DOCTYPE html><html lang="en"><head>  <meta charset="UTF-8">  <title>Document</title>  <script src="../js/vue1.0.js"></script>  <script>    //子組件獲取父組件的值    window.onload = function () {      var vm = new Vue({        el: '#box',        data: {          a: 'aaa'        },        components: {          'aaa': {            data(){              return {                msg: 111,                msg2: '這是父組件的數據'              }            },            template: '#aaa',            components: {              'bbb': {                //html中的my-msg這種形式,js中應該采用駝峰命名myMsg                props: ['mmm', 'myMsg'],                template: '<h3>我是bbb組件->{{mmm}}<br>{{myMsg}}</h3>'              }            }          }        }      });    }  </script></head><body><div id="box">  <aaa>  </aaa></div><template id="aaa">  <h1>11111</h1>  <bbb :mmm="msg2" :my-msg="msg"></bbb></template></body></html>
<!DOCTYPE html><html lang="en"><head>  <meta charset="UTF-8">  <title>Document</title>  <script src="../js/vue1.0.js"></script>  <script>    //子組件獲取父組件的值    window.onload = function () {      var vm = new Vue({        el: '#box',        data: {          a: 'aaa'        },        components: {          'aaa': {            data(){              return {                msg: 111,                msg2: '這是父組件的數據'              }            },            template: '#aaa',            components: {              'bbb': {                //html中的my-msg這種形式,js中應該采用駝峰命名myMsg                props: ['mmm', 'myMsg'],                template: '<h3>我是bbb組件->{{mmm}}<br>{{myMsg}}</h3>'              }            }          }        }      });    }  </script></head><body><div id="box">  <aaa>  </aaa></div><template id="aaa">  <h1>11111</h1>  <bbb :mmm="msg2" :my-msg="msg"></bbb></template></body></html>
<!DOCTYPE html><html lang="en"><head>  <meta charset="UTF-8">  <title>父組件獲取子組件的值</title>  <script src="../js/vue1.0.js"></script>  <script>    //父組件獲取子組件的值    window.onload = function () {      var vm = new Vue({        el:'#box',        data:{          a:'aaa'        },        components:{          'aaa':{            data(){              return {                msg:111,                msg2:'我是父組件的數據'              }            },            template:'#aaa',            methods:{              get(msg){                this.msg = msg;              }            },            components:{              'bbb':{                data(){                  return {                    a:'我是子組件的數據'                  }                },                template:'#bbb',                methods:{                  send(){                    this.$emit('child-msg',this.a);                  }                }              }            }          }        }      });    }  </script></head><body><div id="box">  <aaa></aaa></div><template id="aaa">  <span>我是父級 -》 {{msg}}</span>  <bbb @child-msg="get"></bbb></template><template id="bbb">  <h3>子組件</h3>  <input type="button" value="send" @click="send" /></template></body></html>

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 洞头县| 海淀区| 河津市| 文昌市| 凤凰县| 平山县| 内黄县| 长沙县| 安义县| 南陵县| 洞头县| 兰州市| 桃园市| 宜州市| 西乌珠穆沁旗| 白河县| 海安县| 西峡县| 新和县| 泰安市| 永胜县| 时尚| 抚顺市| 昌黎县| 汪清县| 睢宁县| 卢湾区| 涟水县| 定结县| 天长市| 绥芬河市| 永康市| 金塔县| 鄢陵县| 水城县| 高安市| 彰武县| 深水埗区| 太仆寺旗| 中牟县| 新源县|