亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

代碼
提交代碼
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <div id="app"> <parent></parent> </div> </body> <script src="https://unpkg.com/vue/dist/vue.js"></script> <script type="text/javascript"> Vue.component('parent', { template: '<div><child :name="name" :count="count" @add="add"/></div>', data() { return { name: '句號', count: 18 } }, methods: { // 父組件通過 @事件名 監聽 // count 表示事件觸發傳遞的參數 add(count) { this.count = count } } }) Vue.component('child', { template: '<div>我是:{{name}}, 我今年 {{count}}歲。<button @click="add">加一歲</button></div>', props: { name: { type: String, default: '句號' }, count: { type: Number, default: 18 } }, methods: { add(){ // add -> 觸發的事件名 // this.count + 1 -> 觸發事件時傳遞的參數 this.$emit('add', this.count + 1) } } }) var vm = new Vue({ el: '#app', data() { return {} } }) </script> </html>
運行結果