如何把孫組件內特定的數據傳給爺組件?
例如
把孫組件的名字傳給爺組件并在爺組件上顯示
思路
<!DOCTYPE html><html lang="en" dir="ltr"> <head>  <meta charset="utf-8">  <title></title>  <script src="https://cdn.jsdelivr.net/npm/vue@2.6.7/dist/vue.js"></script> </head> <body>  <div id="app">   child name: {{child}}   <parent v-on:say2='greeting("child", $event)'></parent>  </div> </body> <script>  Vue.component('parent', {   template: `   <div>    <child v-on:say1='$emit("say2", $event)'></child>   </div>   `  })  Vue.component('child', {   template: `    <div>     child     <button v-on:click='$emit("say1", "Jack")'>greeting</button>    </div>   `  })  new Vue({   el: '#app',   data: {    child: '',   },   methods: {    greeting: function (key, value) {     this[key] = value    },   }  }) </script></html>以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。
新聞熱點
疑難解答