What steps should I take to move the content to the bottom of the page once the promise is fulfilled within the function?

I have a showBoxConfirm function that confirms user actions. After clicking the button, it triggers the clickMethod function. The result variable will store the confirmation response, and if it returns false, the function will terminate. However, the showBoxConfirm method is a promise. How can I make sure that the condition works after the response is returned?

<template>
  <div>
     <button @click="clickMethod()"> Click </>
  </div>
</template>

<script>
  export default {
    methods: {
      clickMethod() {
         let result = this.showBoxConfirm();
          // Ensure the condition works after the response is returned

          if (!result) return;
      },
      showBoxConfirm() {
        const h = this.$createElement;
        // Using HTML string
        const titleVNode = h("div", {domProps: {innerHTML: "Title from <i>HTML<i> string"}});
        // More complex structure
        const messageVNode = h("div", {class: ["foobar"]}, [
          h("b-img", {
            props: {
              src: "https://picsum.photos/id/20/250/250",
              thumbnail: true,
              center: true,
            },
          }),
          h("p", {class: ["text-center"]}, [
            "Question text?",
          ]),
        ]);
        // We must pass the generated VNodes as arrays
        this.$bvModal
          .msgBoxConfirm([messageVNode], {
            title: [titleVNode],
            size: "sm",
            buttonSize: "sm",
            okVariant: "danger",
            okTitle: "YES",
            cancelTitle: "NO",
            footerClass: "p-2",
            hideHeaderClose: false,
            centered: true,
          })
          .then((value) => {
            return value;
          })
          .catch((err) => {
            // Handle any errors that occur
          });
      },

    },
  };
</script>

Answer №1

There are 2 issues that need fixing in your code: 1) showBoxConfirm does not include a return statement, causing it to return undefined, which is considered falsy. 2) clickMethod does not wait for a response and moves on immediately after showBoxConfirm returns.

To address the first issue, simply add a return statement at the beginning of your this.$bvModal line. This will return the Promise generated by the catch method. Alternatively, you can eliminate the then and catch calls and directly return the Promise from msgBoxConfirm.

To resolve the second issue, I recommend converting clickMethod into an async function and using await on the Promise returned by showBoxConfirm. You can also utilize the Promise's then method to specify a function to execute upon resolution.

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

md- The datePicker component consistently encounters errors with Date instances

I encountered an issue where the error message The ng-model for md-datepicker must be a Date instance. Currently the model is a: string appeared. I am utilizing moment.js library to handle dates. Within the view section: <md-datepicker ng-model="Model ...

The renderToString function in Material UI's sx property doesn't seem to have

Every time I apply sx to a component that is rendered as a string and then displayed using dangerouslySetInnerHtml, the styles within the sx prop do not work. Here is an example showcasing the issue: Codesandbox: https://codesandbox.io/p/sandbox/wonderfu ...

Error message in Angular js: Unable to load file using XMLHttpRequest

Encountering an error while debugging an Angular JS application in the WebStorm IDE. The error message states: "XMLHttpRequest cannot load file:///C:/Users/../list.html. Cross origin requests are only supported for HTTP." Provided Javascript code : var a ...

Encountering issues with Jquery while retrieving data from a .json URL

While attempting to retrieve data using a small script that usually works with URLs producing JSON data, I encountered a syntax error when trying it with a URL ending in .json. //error Uncaught SyntaxError: Unexpected token : http://frontier.ffxiv.com/wo ...

Using Sequelize to update all values in a JSON file through an Express router.put operation

I've been working on a feature in my Express router that updates data in a MySQL schema for 'members' of clubs. The members table has various columns like member_id, forename, surname, address, etc. I've successfully created an Express ...

Issues with Node AssertionErrors cause failures to be silent and prevent proper error output

I am facing an issue with a particular method in my code. The code snippet is as follows: console.log('Trouble spot here') assert(false) console.log('Will this show up?') Upon running this code within my application, the followi ...

Managing errors in jQuery's .ajax function

Having some issues with jQuery.ajax() while trying to fetch an html code snippet from table_snippet.html and replacing the element in my html code. The error handler in jQuery.ajax() gets triggered instead of the expected success handler. <!DOCTYPE H ...

Binding Font Awesome icons in Vue.js

Recently, I made some changes to my code that is similar to the Simon game. Initially, everything was running smoothly with buttons for the arrows and using the @mousedown event. However, in an attempt to enhance the appearance by incorporating font awesom ...

What is the process for clearing the input value of a View from another View?

My situation seems simple and straightforward, yet I am struggling to achieve the desired output. In this scenario, I have two HTML pages named Index.htm and Main.htm, as well as a script page named mscript.js. Index.htm contains a button (Clear), and Mai ...

Adjusting the slider with jQuery and CSS to extend beyond 100% while remaining within the div boundaries

Currently, I'm working on customizing a jQuery slider. My goal is to achieve the same functionality as the jQuery UI slider where you can set a max value like "2500" and the slider will smoothly adjust without going outside of the specified div or scr ...

Ensure the accurate port is specified in JavaScript to connect to a WCF service

I am working on a JavaScript project where I need to check which port number a WCF service is hosted on, out of a list of 10 different port numbers. I want to find out which port number the service responds to without any errors using AJAX JSON. Although ...

Create spinning wheel - canvas

Hey there! I'm trying to create a cool spinning wheel using a canvas and JS. My wheel is supposed to have 10 segments, each saved as a .png file. https://i.sstatic.net/glN1p.jpg In order to achieve a "full circle", I want to draw these 10 segments i ...

AngularJS validation for minimum character count prevents character overflow

Encountering an unusual "issue". I've set up a form with a textarea that has both a minlength and maxlength validation. In addition, there's a straightforward character count displayed: <textarea ng-trim="false" ng-model="form.text" minlengt ...

Tips on saving php variable content in HTML "id"

Three variables are used in PHP: message_id, message_title, and message_content. Their content is stored inside HTML 'id' for later use with jQuery. Example: Variables: $id_variable = $rows['id_mensagem']; $message_title_edit = $rows ...

using eloquent in vuejs to fetch database columns

I am currently attempting to retrieve data from a database using an AXIOS get request. I have two models, Content and Word, which have many-to-many relationships. In my controller, I am trying the following: public function fetchCourses(){ $dayOne = C ...

Using AngularJS to filter an array using the $filter function

Looking for a more elegant way to achieve the following task: myList.forEach(function(element){ if (!['state1', 'state2'].contains(element.state)){ myFilteredList.push(element) } }) I was thinking of using $filter('fi ...

Javascript challenges for beginners in coding world

After running the code snippet, I encountered the following error messages: at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Fun ...

Is it possible to validate a template-driven form without using the model-driven approach?

Attempting to validate a template-driven form in Angular without two-way data binding has proved to be challenging. I have successfully implemented validation using [(ngModel)], but running into an error when trying to validate the form without the MODEL p ...

Choosing specific content from a different div in JavaScript based on the line number

I have a question regarding two div elements, div1 and div2. I am trying to develop a function where in div2, I can specify the line number of div1 and display the relevant content from that specific line. Currently, I have created a function that successf ...

VueJs with typescript encounters issues with recursive child components, resulting in a warning stating "Unknown custom element" being thrown

I am currently working on a dynamic form that is generated by a DataTypeObject (dto). I have encountered an issue with a warning message while creating recursive components. This warning points to a list of components with the same type as their parent: ...