Change reference of parent component in child component using Vue 3
P粉615886660
P粉615886660 2023-12-05 14:45:34
0
2
545

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粉615886660
P粉615886660

reply all(2)
P粉312631645

In parent

sssccc

In the navigation bar

sssccc

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

for you
P粉521697419

You can tell from your child Navbar.vue


  Logout 

and

sssccc

Then you would use Navbar.vue in the parent


.
.
.

sssccc
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!