Question:
How can I replace this.$parent in composition API in Vuejs?

In Vue 3, consider using> >component events instead.

So, here's the recommended way to replace this.$parent in composition API in Vuejs:


Parent.vue

<script setup>

import IndexComponent from "./IndexComponent.vue";

const parentLog = () => {

    console.log('this is parent component');

}

</script>

<template>

    <div >

        // parent component handle event from child component

        <index-component @log="parentLog" />

    </div>

</template>


Child.vue

<script setup>    

//define your events here

const emit = defineEmits(['log'])


function emitEvents() {

  // emit event from child component

  emit("log")

}


emitEvents()

    </script>

    <template>

        <div >

                <h1> Bla Bla <h1>

        </div>

    </template>


Suggested blogs:

>How to tell Django "if anything in urlpatterns does not match the GET string?

>How can I browser to render links in streamed content in Django?

>Access the "model" attribute for a ListView in Django for template

>How to use a function to print S3 data to HTML using Django?

>How to make a code executed after an entry is inserted, removed or updated?

>How to insert new data into the table in Django?


Ritu Singh

Ritu Singh

Submit
0 Answers