In my VueJs project, I developed a custom button component that includes a loader feature. I initially passed the loader as a prop, but I am currently facing challenges integrating it with a method in another VueJs page

Here is an example of my component:

<button
class="BtnLoader btn btn-primary-contained btn-iconed btn-mobile btn-important"
@click="onClick"
:aria-label="label"
:title="title">
<i v-if="loader" class="spinner icon-spinner3"></i>
<span v-if="loader" class="followingText">{{ textBtnLoader }}</span>
<span v-else class="followingText">{{ textBtn }}</span>
<i class="icon icon-arrow-right"></i>

The current behavior is not what I expected, as it only works with true or false values for the loader property. How can I pass this behavior to my method?

I want to be able to modify the loader status in my method like this:

<BtnLoader
      label="test"
      title="test BTN"
      textBtn="TEST BTN"
      textBtnLoader="Loading"
      :onClick="test"
      :loader="false"
    />

  test() {
  this.loader = !false;
  setTimeout(() => {
    alert('test btn');
  }, 2000);
  this.loader = !true;
},

Answer №1

Give this a shot:

tryOut() {
  setTimeout(() => {
    alert('click me');
  }, 2000);
  this.flag = !this.flag;
},

Remember to delete the v-bind from flag, so it should be just flag="false" instead of :flag="false". Vue will interpret true as primitives without v-bind, otherwise as variables or functions

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

Angular 6 TypeScript allows for efficient comparison and updating of keys within arrays of objects. By leveraging this feature

arrayOne: [ { id: 1, compId: 11, active: false, }, { id: 2, compId: 22, active: false, }, { id: 3, compId: 33, active: false, }, ] arrayTwo: [ { id: 1, compId: 11, active: true, }, { id: 2, compId: 33, active: false, ...

Mastering Cookies in Javascript

I have been exploring the world of cookies in Javascript and decided to create an experimental log-in page. The page is fully functional, but I am interested in displaying the user's username and password using cookies. Is this possible with Javascrip ...

Ways to invoke a next.js api that implements next-auth programmatically

In my next.js app, I have integrated next-auth which is set up to allow authentication using Facebook and Google as providers. Additionally, there are some endpoints located in the pages/api folder of the app. These endpoints are accessed from standard ne ...

Transmit information to a Django UpdateAPIView using Axios

Currently, I am including the Email in the body of an Axios patch request. const userData = await this.$axios.patch(`/user/${id}/update/`, { email: value }) This data is being sent to the specified API View within Django Rest Framework. ...

An issue encountered with getServerSideProps in NextJS 12 is causing a HttpError stating that cookies are not iterable, leading

Currently, I have an application running smoothly on my localhost. However, when it comes to production, an unexpected error has popped up: Error: HttpError: cookies is not iterable at handleError (/usr/src/.next/server/chunks/6830.js:163:11) at sendReques ...

How can I loop the keyframe animation across various elements of an SVG file simultaneously?

After creating an animation using CSS and SVG, I am experiencing different parts of it animating in and out. My goal is to have the animation start from the top once it's finished. There are multiple keyframes involved since I'm animating variou ...

Resource is used to return an array as an object

There is something peculiar going on. I have come across an array structured like this: => [ "optionalinformation" => [ "domain" => [ "type" => "string", ], ], ] This particular array is utilized by a reso ...

Maintain the expanded menu even after selecting a sub-item using jQuery

After conducting a thorough search, I was unable to find exactly what I needed. I have successfully implemented cookies on my menu so that when the page is reloaded, it remembers which menus were open. However, I noticed that clicking on a sub-item of Hy ...

Guidelines for choosing and uploading a file using Ionic

Is there a way to upload a PDF file to a server using the $cordovaFileTransfer plugin? I currently have an input field like this: <input type="file" onchange="angular.element(this).scope().fileNameChanged(this)"> How can I retrieve the pathForFile ...

Is it possible to conceal or encrypt JSON data or header information in HTTP requests and calls?

I am currently developing a full stack website with Flask, Vuejs and SQLite3. I have been using axios to make backend calls from the frontend. However, I noticed that when I make 'GET' requests using axios (Vuejs) to the backend on a particular r ...

Opinions on crafting a new gadget?

I will only provide each website interested in my widget with the code to copy and paste once. It is crucial that the code is future-proof. After much consideration, this is the widget code I have developed: <script type="text/javascript" src="http:/ ...

Cross domain request in a simple HTML document

I'm currently working on an app that is strictly in plain HTML files without a server. I'm facing difficulties with cross domain requests from JavaScript. Whenever I try to make a request, the browser displays this error message: XMLHttpRequest ...

Display a fancy slideshow that transitions to five new images when the last one is reached

Here is a screenshot of my issue: https://i.stack.imgur.com/duhzn.png Incorporating Bootstrap 3 and FancyBox, I am facing an issue with displaying images in rows. When I reach the last image, clicking on the right arrow should result in sliding to anothe ...

Guide on uploading a file to Pinata directly from a React application

I keep encountering the 'MODULE_NOT_FOUND' console error code. Displayed below is the complete console error: > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3f4b4d564b5a4d4d5e4c1251505b5a7f0e110f110f">[email& ...

Error message: jQuery expression not being detected

Here is some html code that I have in my view: <div id="divLoginName" style="display: none"> <input type="hidden" id="hidLoginName" /> @Html.TextBox("txtEditLoginName", null, new { maxlength = "1000", tabindex = "0", Multiline ...

The Evolution of Bulma's Navigation Menu

Creating a transparent menu in Bulma has been successful for the desktop viewport: VIEW DESKTOP MENU However, when attempting to implement the same design on mobile, the menu ends up like this: VIEW MOBILE/TABLET MENU The mobile version seems to inheri ...

`Javascript framework suggests ajax navigation as the preferred method`

What is the best way to handle ajax navigation using jQuery? I have recently experimented with a simple jQuery ajax code to implement ajax-based navigation for all the links on a webpage. $('a').click(function(e){ e.preventDefault(); ...

When running npx webpack, an error occurred stating, "Property 'minify' cannot be read from undefined."

I've been following the introductory tutorial on webpack from this particular link: https://webpack.js.org/guides/getting-started/ However, when I attempt to execute npx webpack, it encounters an error as shown below: ERROR in main.js from Terser Ty ...

Developing a Customized Modal with Backbone.js

As a newcomer to Backbone, I have been trying to create a Modal in my application by setting up a base Modal class and then extending it for different templates. However, despite conducting some research, I haven't been able to find a solution that fi ...

Updating the columns in a row by clicking the refresh button with ajax in a JSP file

Hey there! I have a table on my JSP page with refresh buttons at the row level. When I click the refresh button, it should check the database and update those two columns with new values. Below is the code snippet for my JSP page: <script src="js/jque ...