Achieve Dual Functionality with Vue.JS Button within a Parent Element

My parent component structure looks like this:

<template>
  <b-container>
    <b-modal id="uw-qb-add-item-modal"
             ref="uw-qb-add-item-modal"
             title="Enter Item Number"
             @ok="handleNewItem">
      <form @submit.stop.prevent="handleSubmit">
        <b-form-input type="text"
                      placeholder="Enter the item number" />
      </form>
    </b-modal>

    // Other code here...

    <b-collapse :id="editId">
      <build-item-edit @doOnEmit="expand" :buildNumber="buildNumber"
                       :itemNumber="editItemNumber"/>                   
    </b-collapse>

    // Other code here...

  </b-container>
</template>

// Child Component

<script>
export default {
  methods: {
    edit(item) {
         const payload = {
        item
    };
      this.$emit('edit', item.itemNumber);
      
      const collapseElement = document.querySelector('#' + this.editId);
      if (collapseElement && !collapseElement.classList.contains('show')) {
        this.$emit('expandCollapse');
      }
      
      this.editmsg = "Edit your item above and then click 'Save Edit'"
    }   
  }
};
</script>

This will now trigger the expand of the toggle collapse on the parent component when the button is clicked in the child component.

Answer №1

Assuming that <build-item-edit> is a custom component you created, you can easily incorporate a callback event into it like so:

<build-item-edit @doOnEmit="executeParentFunction" :buildNumber="buildNumber" :itemNumber="editItemNumber"/>

In the parent component, define the method executeParentFunction and include the code to handle your UI actions.

Before emitting the value in the build-item-edit component, remember to call this.$emit('doOnEmit').

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The Ajax database browser page refresh feature updates the content without actually refreshing the entire page

I am encountering an issue with my AJAX and PHP database integration. I believe many novice Ajax programmers are facing a similar problem. Despite shortening the code, it remains lengthy so please bear with me. There's a button on the homepage index.p ...

How to divide styles using dynamic columns

Is there a way to create dynamic columns with different CSS styles for each item in Vue? I can easily achieve this when all items have the same style, but what if I want each item to have unique styling while still being in a column layout? This is what I ...

Utilizing the NestJS Reflector within a Custom Decorator: A Comprehensive Guide

I have implemented a solution where I use @SetMetaData('version', 'v2') to specify the version for an HTTP method in a controller. Additionally, I created a custom @Get() decorator that appends the version as a suffix to the controller ...

No files located by the server

My experience with writing a basic express script to serve a webpage with embedded Javascript has been quite frustrating. The server seems to struggle finding the files I provide, and what's even more aggravating is that it sometimes works but then su ...

Troublesome Issue with ngAnimate and ngHide: Missing 'ng-hide-animate' Hook Class

I am working on a case where I need to add animation to a DOM object using the ngHide directive: Check out this example here Within this scenario, I have an array of JSON objects: $scope.items = [ {"key": 1, "values": []}, {"key": 2, "values": [ ...

Utilizing Vue.js to initiate a server request with vue-resource

Seeking guidance on performing a server call using vue-resource. I'm unsure about how to set the header and send data via Vue.$http.post Vue.$http.post('http://url/', { email: 'foo', password: 'bar' }, { headers: { ...

Guide on how to load just the content section upon clicking the submit button

Here is an example of my code: <html> <head> <title>Test Loading</title> </head> <body> <div id="header"> This is header </div> <div id="navigation" ...

What is the best way to send an object to Vue Component?

How can I properly call a Vue Component with a data object? The todo-item tag works as expected, but the todo-item2 tag does not produce any output. I was expecting the same result. Here is the HTML code: <div id="app"> <todo-item v-bind:te ...

Having trouble with JQuery toggle()? Need some assistance with fixing it?

My attempts to utilize JQuery toggle functionality have been unsuccessful. The sliding up and down animation is not smooth and instead happens very quickly. I aim to achieve a sliding effect in my code similar to this example (Please refer to Website Des ...

Issues arise when attempting to compile the .vue extension with Laravel Webpack mix.js

Just starting out with webpack in Laravel and I've successfully compiled the default scripts into one file. However, I'm running into an issue when trying to add a new Vue Controller in a separate folder - it doesn't seem to be included duri ...

Transferring information from a Nuxt module to a plugin

I have been working on passing data from my module options to a plugin. Here is an example of how I am doing it: module.exports = function (moduleOptions) { const options = { ...this.options.moduleName, ...moduleOptions } this.addPlugin({ ...

What steps can I take to guarantee that a select change event occurs following the setting of ngmodel in Angular2?

I am facing an issue with a select element wherein a basic (change) handler is attached along with an ngmodel. Whenever an <option> with a ng value is set, the change handler triggers before the [(ngModel)] reflects the new values. <div> ...

Implementing code to scroll and play multiple videos simultaneously using JavaScript and jQuery

This solution currently only works for one video, but it needs to be able to handle multiple videos (TWO OR MORE) <html> <head> <script src="https://code.jquery.com/jquery-1.8.0.min.js" integrity="sha256-jFdOCgY5bfpwZLi ...

Unable to retrieve element using jQuery because it is specified by its href attribute. This pertains to

I'm having trouble accessing the "a" element with its href attribute. Specifically, I want to add a class to any element that has an href value of "#one". Check out this jsFiddle example. Using jQuery: // The tabs functionality is working correctly ...

The tabbing feature in bxslider disrupts the alignment of slides, making it

After encountering accessibility issues, I upgraded the bxslider library to version 4.2.3 for better support. Check out this example of bxslider where you can easily tab through the controls: http://jsfiddle.net/qax7w8vt/2/embedded/result/ The problem a ...

What is the process of naming a component in the setup tag of Vue3?

Within the export default {} approach, there is a name property used to specify the component name for Vue Devtools. However, what would be the equivalent in the new <script setup> syntax? https://i.sstatic.net/M9Q8x.png ...

Encountering difficulties in accessing files displayed by serve-index in Express

My Node.js server using Express seems to be working fine for displaying directory contents, but I'm running into an issue when trying to access individual files. After clicking on a file listed in the directory, I keep getting an error message that sa ...

Express: How to Define Route Parameters from the Client Side

app.get('login/:id', function (request, response) { … }); I am curious about how the :id parameter is assigned from the user in a request like this. Since each user will have a unique id on my site, I wonder how it works. Does the user need ...

Utilizing Sails.js: Invoking a YouTube service through a controller

I am facing an issue while trying to integrate Youtube Data API with Node.js in Sails.js. The problem lies with the "fs.readFile" function. Upon launching the service, it returns "undefined". Below is the code snippet for YoutubeService : module.exports ...

React JS simple validator package not functioning properly with post-property date

I am currently utilizing the simple react validator package for form validation in my react JS project. For those interested, you can find the package at this link: https://www.npmjs.com/package/simple-react-validator However, I have encountered an issue w ...