Vue method not being triggered despite emit in inline template

Trying to figure out what I'm missing here, it seems like this should be the solution: Vue: method is not a function within inline-template component tag

Yet, the method still isn't working as expected.

  <b-table
      :items="filtered"
      :fields="fields"
      sort-icon-left
      responsive="sm"
      @card-click="setUpdate"
    >
      <template v-slot:head()="data">
        <span class="text-info">{{ data.label.toUpperCase() }}</span>
        <button @click="$emit('card-click', data)">filter</button>
        <input
          v-show="data.field.showFilters"
          v-model="filters[data.field.key]"
          :placeholder="data.label"
        />
      </template>
    </b-table>

  methods: {
    setUpdate(field) {
      console.log("hello");
      console.log(field);
      this._originalField = Object.assign({}, field);
      field.showFilters = true;
    }
  }

Update:

Using @click helped trigger the event, but then the table wouldn't update with the modified data containing showFilters. Thanks to MattBoothDev, I came across event-based-refreshing-of-data, which unfortunately now prevents the data from changing. For instance, if field.showFilters is true, it remains true even after clicking the button.

 methods: {
    setUpdate(field) {
      this._originalField = Object.assign({}, field);
      field.showFilters = !field.showFilters;
      this.refreshTable();
      console.log(field.showFilters);
    },
    refreshTable() {
      this.$root.$emit("bv::refresh::table", "my-table");
    }
  }

Answer №1

It appears that Bootstrap Vue is being utilized in this case.

The current setup involves placing a listener on the <b-table> tag for the card-click event, even though this event is not occurring within a child component of <b-table>.

However, it seems that the event may not even be necessary.

Instead of using

<button @click="$emit('card-click', data)">filter</button>
, you can simply use
<button @click="setUpdate(data)">filter</button>
.

UPDATE:

It is recommended to employ the MVVM pattern in Vue.js development as well.

Instead of:

@click="$emit('card-click', data)"
,

Consider using: @click="onFilterClicked".

Then:

methods: {
  onFilterClicked (data) {
    this.$emit('an-event', data.some.property)
  }
}

This adjustment will facilitate testing of your code.

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

Exploring the FunctionDirective in Vue3

In Vue3 Type Declaration, there is a definition for the Directive, which looks like this: export declare type Directive<T = any, V = any> = ObjectDirective<T, V> | FunctionDirective<T, V>; Most people are familiar with the ObjectDirectiv ...

What is the process for implementing a grid with 5 columns on larger screens and 2 columns on smaller screens using reactjs?

I am currently working on building a Grid using material UI and reactJs. I found the guidelines on this link https://mui.com/system/react-grid/. However, there seems to be an issue with creating 5 columns in the grid. I attempted to create a custom grid ...

What is the reason that when the allowfullscreen attribute of an iframe is set, it doesn't appear to be retained?

Within my code, I am configuring the allowfullscreen attribute for an iframe enclosed in SkyLight, which is a npm module designed for modal views in react.js <SkyLight dialogStyles={myBigGreenDialog} hideOnOverlayClicked ref="simpleDialog"> <if ...

Delete the final comma in a JSON file using JavaScript so that it can be utilized by a Vue application

Using Axios in my Vue app, I am consuming a JSON file. The field "country" contains trailing commas which are creating issues. Here is the structure of the JSON: "country": "spain,france," .... "country": " ...

AngularJS animate issue: TypeError - method 'classNameFilter' not found

When I added ngAnimate to my AngularJS app.js file as documented, I encountered a peculiar error: Object [object Object] has no method 'classNameFilter' - angular-animate.js:297 Any idea why this is happening? This is the code snippet where I ...

"Implement a smooth scrolling animation on the page to automatically move a div element upward and lock

I am attempting to create a unique animation for a header div that involves moving it to the top of the screen when the user scrolls down. Once the header div reaches the top, I want it to stay fixed in that position. As the header div moves upwards, it wi ...

Decide whether to fulfill or deny a Promise at a later time in

When working on an Angular2/TypeScript project, a dialog is shown and the system returns a Promise object to the caller. This Promise will be resolved after the user closes the dialog. The interface of the Promise class does not include methods like resol ...

Learn the steps to initiate a Vimeo video by simply clicking on an image

I have successfully implemented some code that works well with YouTube videos, but now I am looking to achieve the same effect with Vimeo videos. Does anyone have suggestions on how to do this? I need to replace the YouTube description with Vimeo, but I&ap ...

What could be causing the issue of opacity and list reordering not functioning properly in react-dnd and react-virtualization?

I'm currently setting up a react-dnd sortable list within a react-virtualized List. I've been referencing an example from react-dnd which can be found here. Most of it is working as expected, but I'm encountering an issue where the items I ...

router.query is returning an empty object when using Next.js

Here is how my folders are organized: https://i.stack.imgur.com/TfBtv.png In addition, here is a snippet of my code: const router = useRouter(); const { id } = router.query; The issue I'm facing is that the id is returning {} instead of the actual ...

VueJS allows for seamless image uploading using either a gallery of images or input files

Is there a way to enable image selection from "Pick from gallery" feature in addition to the file upload functionality demonstrated in the example below? I would like the same behavior for selecting an image from the gallery as when uploading a file using ...

What is the process for adding text before and after a Bootstrap progress bar?

I want to customize the bootstrap progress bar with text at the beginning and end, like this: 5 star ----------------------------------------------- 70% Here is my attempt to achieve this: <link rel="stylesheet" href="https ...

Having trouble receiving any ringing status in nextjs while utilizing the getstream SDK

I attempted to integrate the getstream video SDK for calling from the caller to the callee. While I can successfully create calls from the caller side, I am not receiving any status updates about the call on the callee side. Below are my codes for the cal ...

Interactive element for initiating a HTTP request to NodeJS/Express server to trigger a specific function

I currently have a frontend button implemented using nodejs and express for my server-side backend. The button is supposed to trigger a function that controls the Philips Hue API on the backend via an HTTP request. I have experimented with various approac ...

A guide on including a node as a parameter, alongside other data types, in a function using ajax within Umbraco

When attempting to pass a node and two strings as parameters to a JsonResult in Umbraco, I encountered an issue where the node variable had no value when debugging the method. Below is the JavaScript code: function newsSub() { if(validateForm('ne ...

Validate whether the path parameter in NextJS is null or empty before executing the query

Currently seeking a method to determine if the query value is empty using the path parameter approach. Have a file named pages/search/[variable1].js Below is the code snippet: import { useRouter } from "next/router" const Variable= () => { ...

Interactively retrieving objects from a JavaScript array based on their keys

let arr = [{id:'one',val:1},{id:'two',val:2}] for( let ii of arr ) { if( ii.hasOwnProperty('id') ) arr[ii.id] = ii } This code snippet allows for accessing the elements in the array by their 'id' key. For exampl ...

What steps can I take to resolve the issue of the "self signed certificate in certificate chain" error while trying to install plugins on VS Code?

After setting up VS Code on my Windows 7 x64 system, I encountered an issue when trying to install plugins - I kept receiving the error message "self signed certificate in certificate chain". Despite setting "http.proxyStrictSSL": false, I was still unable ...

What does the single-threaded nature of JavaScript signify in terms of its intricacies and ramifications?

As someone relatively new to Javascript and JQuery, I recently discovered that Javascript operates on a single-threaded model. This has left me wondering about the implications it carries: What should be taken into account when writing JavaScript code? Ar ...

utilizing mongoose populate for displaying the author

One of the features on my website allows users to add notices, and I want the page to display the author of each notice. const notices = await Notice.findById(id).populate('author'); When I access this route, I can successfully log the authors o ...