Utilizing a function from a separate file in Vue: A step-by-step guide

Recently starting to work with Vue, I encountered an issue while trying to utilize a helper function called arrayDateFormatter within one of my imported .vue files. Despite importing it, the function doesn't seem to be called when used inside the mounted() method, and nothing executes after it. Interestingly, no errors are displayed in the console.

Here is a snippet from my Vue file:

<template>
.....
</template>

<script>
import archives from "@/4.objects/o-archives";
import fullBanner from "@/4.objects/o-full-banner";
import speakerInfo from "@/4.objects/o-speaker-info";
import newsletter from "@/4.objects/o-newsletter";
import dataLoaderMixin from "@/mixins/dataLoader-mixin";
import arrayDateFormatter from "../mixins/gloabalEventsDateFormate-mixin";

export default {
  components: {
   ....
  },
  mixins: [dataLoaderMixin],
  data() {
    return {
      speakers: [],
      talkInfo: null,
      archives: []
    };
  },
  async mounted() {
    try {
      const response = await this.fetchEventsByProject();
      console.log(response.data.data.listOnlineEvents.items);
      //nothing gets triggered after here
      const currentEvent = arrayDateFormatter(response);
      console.log('current event');
      console.log(currentEvent);
      this.archives = this.fetchData("archive");
    } catch (err) {
      return err
    }
  }
};
</script>

Here's the code for the helper function:

export const arrayDateFormatter = (response)=> {
 //some code i have tested and it works by itself
}

Answer №1

It seems that importing the files in this manner is necessary.

import {arrayDateFormatter} from "../mixins/globalEventsDateFormate-mixin";

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

JavaScript unable to remove cookie from system

I'm currently on an external website and attempting to use JavaScript to remove a cookie. Here's what I tried in the console: function deleteAllCookies() { var cookies = document.cookie.split(";"); for (var i = 0; i < cookies.length ...

retrieve JSON object from deferred response of AJAX request

After utilizing Ajax to send an item to a SharePoint list, I aim to incorporate the jsonObject received in response into a list of items. Located in AppController.js $scope.addListItem = function(listItem){ $.when(SharePointJSOMService.addListIte ...

Steps for loading a different local JavaScript file by clicking on a button

My goal is to reload the browser page and display a different ReactJS component/file when a button is pressed. Initially, I attempted using href="./code.js" or window.location="./code.js" within the button props, but unfortunately, it did not yield the des ...

Raspberry Pi 4: My LED is only blinking 8 times instead of the expected 16 times

I have encountered an issue with my program run, compilation, and result. In the screenshot below, you can see that my LED is only blinking 8 times instead of the anticipated 16 times. My expectation was for the LED to blink every 0.25 seconds for a total ...

What is the best way to position a container div over another container using Bootstrap or CSS?

https://i.sstatic.net/q1qGi.png I'm working on a Bootstrap 4 layout where container B needs to overlay part of container A. I want to achieve a design where container B appears on top of container A. Any suggestions or references on how to achieve th ...

Accessing a Vue instance in Vue Router using Vue 3. Beyond the confines of a Vue file

I've been struggling with this issue for a while now. My goal is to access my Keycloak instance from within the Vue router.js file. const preventRoutes = { beforeEnter: (to, from, next) => { console.log(App.$keycloak.authenticated); //this re ...

CarouFredSel Transition Troubles

I am currently using CarouFredSel to create an image carousel, but I am encountering some issues with the transitions between items. My goal is to incorporate simple HTML elements into the carousel instead of just plain images. However, when I attempt to ...

Incorporate communication between the front-end and backend

I encountered an error while attempting to import the getUser function in my backend code. The actual function is located in the frontend at ../utils/auth. How can I successfully import between front-end and backend? Or might there be another issue at pla ...

What could be causing the issue with Collection.find() not functioning correctly on my Meteor client?

Despite ensuring the correct creation of my collection, publishing the data, subscribing to the right publication, and verifying that the data was appearing in the Mongo Shell, I encountered an issue where the following line of code failed to return any re ...

Nuxt Js - Ensuring script is only loaded once during the initial page load

I already have a static website design, but now I'm converting it to Nuxt.js to make it more interactive. After running my Nuxt server with "npm run build...npm run start," the scripts load and my carousel/slides work fine. However, when I navigate to ...

Error message: When using Vue CLI in conjunction with Axios, a TypeError occurs stating that XX

I recently started working with Vue.js and wanted to set up a Vue CLI project with Axios for handling HTTP requests. I came across this helpful guide which provided a good starting point, especially since I plan on creating a large project that can be reus ...

Arranging Functions in JavaScript

I am encountering an issue regarding the execution of JavaScript functions within HTML. Specifically, I am using dimple.js to create a graph and need to select an svg element once the graph is created via JavaScript. Despite placing my jQuery selector as t ...

Having issues with triggering a function from child props in React

I've been working on firing a function from an onClick event in a child component. getTotalOfItems = () => { console.log('anything at all?') if (this.props.cart === undefined || this.props.cart.length == 0) { return 0 } else { ...

Find all objects in an array of objects that contain at least one value that matches a given string

I am currently integrating search functionality in my application. The UI search results are generated from an array of objects. My goal is to loop through the name, custNumber, and sneak values in each object and display only the ones that contain a subst ...

Hovering in Javascript

Imagine I have the following code snippet: <div class="class1"> ... random content </div> I want to use JavaScript so that when I hover over that div, a CSS attribute is added: background-color:#ffffe0; border:1px solid #bfbfbf; This is a ...

Mobile Devices Experience AJAX Failures

My AJAX requests are not working properly on mobile browsers and iPads, but they work perfectly on desktop computers. I am struggling to figure out what the issue might be. var xmlhttp; if(window.XMLHttpRequest){ xmlhttp = new XMLHttpRequest(); }else{ ...

Simple method to retrieve the ID of an input field within a form using jQuery selectors

I have a form with each input field having a unique id, and I have attached a jQuery 'input' event to the form. I want to retrieve the id of the field on which the user changes some value using a jQuery function. There seems to be something missi ...

Activate button through input using Bootstrap

I am struggling to achieve the desired functionality with my "sendit" button. I want it to be enabled as soon as there are any characters entered in the box, but I have tried multiple solutions without success. Part of HTML: <input type="password ...

Pinia seems to be failing to refresh and display the latest image

My store and state is updating correctly. I'm currently using Ionic along with vue.js composition using Pinia. After making a selection on a previous route to choose a new image, the image gets updated properly in pinia, but it does not reactively ch ...

Preserve file sequence with jquery file upload

I recently came across an interesting upload script at the following link: This script utilizes jquery file upload to allow for uploading multiple files simultaneously. I'm curious about how to transmit the order in which the files were selected to t ...