Is it possible for me to access both the previous and current values from the watcher within the mounted lifecycle?

I want to utilize this.prev and this.curr in the mounted cycle, incorporating the updated changes from the watcher. How do I access these current values in the mounted cycle?

 <template>
  <component
    :is="'nuxt-link'"
    :to="{ path: slug, query: { scroll: 'false' } }"
    :class="linkClasses"
    v-on:click.native="getSelectedFacet($event.target.textContent)"
  >
    <slot></slot>
  </component>
</template>

<script>
export default {
  inject: ["filterVariantState"],

  props: {
    facetKey: {
      type: String,
      required: true,
    },

    // other prop definitions...

  },

  data() {
    return {
      trackFacets: [],
      showAnimation: false,
      updatedFacet: null,
      updatedFacetKey: null,
      prev: {
        attributes: [],
        name: "",
      },
      curr: {
        attributes: [],
        name: "",
      },
    };
  },

  computed: {
    // computed properties...
  },

  methods: {
    // methods...
  },

  watch: {
    dataObj(newVal, oldVal) {
      this.prev = {
        attributes: Object.values(oldVal.attributes),
        name: this.dataObj.name,
      };
      this.curr = {
        attributes: Object.values(newVal.attributes),
        name: this.dataObj.name,
      };
    },
  },

  mounted() {
    let n = 1;
    let queue = [];

    for (let i = 1; i <= n; i++) {
      let prevFacets = this.prev.attributes;
      let currFacets = this.curr.attributes;

      console.log("prev", this.prev.attributes);
      console.log("curr", this.curr.attributes);

      for (let j = 0; j < prevFacets.length; j++) {
        queue.push(prevFacets[j]);
      }

      for (let k = 0; k < currFacets.length; k++) {
        queue.push(currFacets[k]);
      }
    }

    // logic for handling animation...

  },
};
</script>>



I experimented with placing my mounted content inside the watcher, but the animation only displays briefly as it needs to be managed within the mounted cycle.

Answer №1

Instead of directly manipulating the data, I chose to send it to the vuex store for storage. This allowed me to access the stored values using a getters function and utilize them in the mounted cycle alongside dynamic changes provided by the watcher function.

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

What is the process for sending an InMemoryUploadedFile to my S3 storage?

My upload form is quite simple and includes an image as a FileField: def post(request): if request.user.is_authenticated(): form_post = PostForm(request.POST or None, request.FILES or None) if form_post.is_valid(): inst ...

Utilize the "v-on:" directive in VueJS to attach an event listener to the <router-link> component

I'm currently working on integrating a custom handler called InlineButtonClickHandler to the <router-link> component's click event. The purpose of this customization is to emit a specific appSidebarInlineButtonClick event. Despite my effor ...

Creating an interactive dropdown menu with simple_form

I am new to JS/Ajax and unsure how to render dynamic options based on previously inserted data in the same form. Background: The bike shop chain application allows the renting of bikes with names like "bike 1" or "yellow bike" ('bikes'), by sele ...

Using jQuery UI to trigger Highlight/Error animations

Apologies if this question seems obvious, but I can't seem to find a clear answer anywhere... Is there a way to add a highlight/error message similar to the ones on the bottom right of this page: http://jqueryui.com/themeroller/ by simply using a jQu ...

Utilizing environment variables in a Rails-AngularJS (1.5) project

Currently working on a Rails-AngularJS (1.5) project and encountering difficulties accessing my ENV variables in the JavaScript components such as services and console. I've implemented dotenv, stored my SECRET_KEY in a .env file, and included the fo ...

Issue with PrimeNG Carousel width on mobile devices

Currently, I am in the process of developing a system interface with Angular and PrimeNG specifically for mobile devices. The main requirement is to have a carousel to display a set of cards. After evaluating different options, I decided to utilize the ngP ...

Is there a way to execute a statement or method after the loop finishes in a Vue component?

Here is an example of my Vue component structure: <template> <div class="row"> <div class="col-md-3" v-for="item in items"> ... </div> </div> </template> <script> export def ...

Setting the background color of a window using Vuetify: a step-by-step guide

I have developed a small Vuetify 2.x application that showcases a list with a dark theme. Whenever I scroll past the end of the list (top or bottom), I notice a brief appearance of a white zone. Is there a way to configure the window background color to ...

"Bootstrap-Wizard: How to troubleshoot the onPrevious function not working when used with an

I have been incorporating a bootstrap wizard into one of my applications, and I have encountered an issue. When attempting to utilize the index position of the tabs to achieve a specific goal, I found that it only works with the next button and not with th ...

What is the method to adjust the color of items within a <select> dropdown menu?

Feeling stuck with a real problem! I have no clue how to solve it... Is it even possible? I want the text in this menu to be white: https://i.sstatic.net/wTqRo.png This is my code: <select id="addRow-fieldType" style="margin-top: 10px; width: 180px; ...

Unable to declare a string enum in TypeScript because string is not compatible

enum Animal { animal1 = 'animal1', animal2 = 'animal2', animal3 = 'animal3', animal4 = 'animal4', animal5 = 'animal5' } const species: Animal = 'animal' + num Why does typescr ...

Listen for submit events on the postMessages element to add new messages

I have a basic HTML 5 form with video API integration. My goal is to have a video play when the user clicks the submit button. Here is an example of the HTML form input: HTML 5 <form> <div class="form-group"> <label for="name" ...

Steps for integrating a login system in an Angular application using an existing REST API backend

My buddy and I are collaborating on an app - he's handling the backend (Node.js) while I'm working on the frontend. He set up sessions on his end and gave me the URL that I need to use for logging in. It's a POST request like this: http:// ...

Searching for text using JQuery autocomplete feature with results fetched from an external source

I am currently working on integrating an input field with autocomplete functionality using the Google Books API to suggest book titles based on user input. My framework of choice for this implementation is Django. So far, I have managed to achieve the fol ...

Learn the steps to upload multiple images to Firebase realtime database with the help of Vuejs

I am currently facing an issue with uploading multiple images to a real-time Firebase database. I have successfully managed to upload one image, but I am unsure how to handle multiple images at once. This is the code snippet for uploading a single image: ...

``In a WordPress plugin, a SELECT query for the database (utilizing WordPress, PHP, and MySQL) is

When trying to fetch records from a select query within a plugin, I encounter an issue where no records are returned and I receive the following error message in the web console. Can someone help me identify what mistake I might be making?: Object { rea ...

Arrangement of jQuery On Events and Triggers

Consider the code snippet below: $('body').on('hellothere', function(){ console.log('execution complete.'); }); $('body').triggerHandler('hellothere'); The abov ...

passing data from the view to the controller

When I choose an option from the dropdown menu, the selected value is not being passed to the controller action method. Although the selected value is binding in Ajax, it is not binding in the controller action method. Check out our page <div class="ro ...

Adjust the size of a Highcharts chart before printing

I'm facing an issue with a chart that doesn't have a specified height or width. My goal is to print the graph in a taller and larger size when I click on the print button. I attempted to use setSize() function, but since there are no original di ...

The initial value for the `useState` is not defined at the

Here's a simplified version of my requirement that demonstrates the issue. The ColorBox component receives a prop called "isVisible" from the ShowColorComponent component, which is used to initially set the state of the ColorBox.visible variable. impo ...