Home  >  Q&A  >  body text

Change reference of parent component in child component using Vue 3

I have a child component called Navbar. Logout is an option in the navigation bar.

<a @click="(event) => {event.preventDefault();}">
  Logout 
</a>

I have imported this Navbar into a parent component named Home. In the Home component, there is a div (a modal box),

<div class="modal" v-if="modal">

This modal will only be displayed if the modal reference is true.

<script setup>
import Navbar from './components/Navbar.vue';
import {ref} from 'vue';

const modal = ref(false);

</scipt>

My question is, how can I set this mode ref value to when we click on the logout option in the Navbar child component true.

P粉615886660P粉615886660319 days ago541

reply all(2)I'll reply

  • P粉312631645

    P粉3126316452023-12-06 10:42:11

    In parent

    sssccc
    

    In the navigation bar

    sssccc
    

    Note@click.prevent=.... - it does preventDefault

    for you

    reply
    0
  • P粉521697419

    P粉5216974192023-12-06 09:00:28

    You can tell from your child Navbar.vue

    
      Logout 
    

    and

    sssccc

    Then you would use Navbar.vue in the parent

    
    .
    .
    .
    
    sssccc

    reply
    0
  • Cancelreply