其他分享
首页 > 其他分享> > vue3 emit事件

vue3 emit事件

作者:互联网

 

   <div id="vm">
        <div>子组件点击时:{{count}}</div>
        <blog-post @myaddevent='fuaddevent'></blog-post>
    </div>
    <script type="module">
        import * as obj from './main.js'
        const app = Vue.createApp({
            data() {
                return {
                    count: 0
                }
            },
            methods: {
                fuaddevent(data) {
                    this.count += data;
                }
            }
        });
        app.component('blog-post', obj.btn1)
        const vm = app.mount('#vm');
    </script>

main.js

const btn1 = {
    template: `<button @click="add(1)">增加</button>`,
    methods: {
        add(num) {
            this.$emit('myaddevent',num)
        }
    }
}
export { btn1 }

 

标签:count,const,methods,app,btn1,事件,vue3,data,emit
来源: https://www.cnblogs.com/buchizaodian/p/14903031.html