49
38

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

子コンポーネントから親コンポーネントのイベントを発火する

Last updated at Posted at 2017-07-31

emit を使う。

子コンポーネント

「追加する」ボタンをクリックすると、親に add というイベントが渡される。

child.vue
<template>
	<button class="button" @click="add">追加する</button>
</template>

<script>
    export default {
        methods: {
            add(){
                this.$emit('add');
            }
        }
    }
</script>

親コンポーネント

addを検知すると addProduct が実行される。

parent.vue
<template>
	<forms @add="addProduct"></forms>
</template>

<script>        
	export default {
		methods: {
			addProduct(){
				console.log("piyo");
			}
		}
	}
</script>        

参考

49
38
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
49
38

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?