Adding a static javascript file to a Vue CLI 3 project is a straightforward process

Currently working on a vue-cli-3 project and looking to include a static javascript file. Curious about the proper way to import this file.

The typical method used is:

<script src="js/myfile.js"></scrip>

Answer №1

To include your file (myfile.js) in your project, place it inside the src directory, for example in assets. In your src/App.vue file, include the following line in the script section:

import './assets/myfile.js';

While technically possible to place your file in the public directory and reference it from your index.html as you normally would, it is not the recommended practice.

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

Modify the button's border color upon click action

I am looking to implement a feature where the border of a button changes when clicked once and reverts back when clicked again. This should apply individually to each of the 16 buttons with the same class. Additionally, I want to enable the ability to clic ...

pause in execution between iterations of a for loop

Challenge I'm currently working on a function that processes a list of strings by printing each one on a new line, with CSS animations that gradually display the string over a few seconds. However, I'm struggling to make sure that the next strin ...

AngularJS and Bootstrap carousel combined for a dynamic multi-item per slide display

Currently, I am utilizing Bootstrap to showcase a carousel on my website, where multiple items are displayed per slide as demonstrated in this example. The use of static images has yielded satisfactory results, as evidenced by the jsFiddle example found he ...

Optimal method for implementing $scope.$apply(); or $scope in scenarios outside of Angular when working with Angular Components

As outlined in Kendo's best practices, there are instances where Kendo necessitates the use of $scope.$apply(); to update Angular. However, with the emergence of the new AngularJS 1.5 component, it is advised against relying on $scope. The code for t ...

Issue with displaying entire object using Jest and console.dir

I'm having trouble displaying an error in my Jest test because it's not showing all the levels as expected. import util from 'util' describe('Module', () => { it('should display all levels WITHOUT util', () =& ...

Enhance the collapsible feature in Vue.js by integrating Bootstrap and anim

In the process of creating a side bar menu with collapse show/hide functionality, I am encountering some issues. The current CSS implementation is making the collapse action appear abrupt and unnatural. I am looking to achieve a smooth sliding transition ...

Unable to modify the state of data in Vue.js

After developing a weather app, I implemented some components with fields in the data section. However, when I changed the value of these fields in the methods section and attempted to access them in another method, I discovered that the old values were be ...

Convert the PHP datetime and timezone function to a JavaScript function

I have a helpful function in my solution that I'd like to share: public static function formatTime($time, $timezone) { $timezone = new \DateTimeZone($timezone); $time = $time->setTimezone($timezone); return \Locale::getDefaul ...

Issues have been encountered with the functionality of the Bootstrap selectpicker library

I am working on a dropdown list forum and want to incorporate a search feature. I decided to implement the selectpicker library for this purpose, but I keep encountering an error in the console that says Uncaught TypeError: Cannot read properties of undefi ...

The hyperlinks on the webpage are not functioning

I am encountering an issue with a link on a particular page. When scrolling down, the link works perfectly; however, when I attempt to scroll up, it remains in the same position. Here is a snippet of the code: (function($){ /* Store the original positions ...

Converting Milliseconds to a Date using JavaScript

I have been facing a challenge with converting milliseconds data into date format. Despite trying various methods, I found that the solution provided in this link only works for a limited range of milliseconds values and fails for higher values. My goal is ...

How can I implement a Vue v-if directive in App.vue, while having a toggle button in a separate component?

I am facing an issue in my App.vue file where I have a v-if condition that is hiding a div when the data returns false. I want to implement a toggle functionality for this, but I would like to place the button in a different component that is imported into ...

Troubleshooting unresponsive buttons within a $timout/ setTimeout function in Angular and Ionic

I am trying to implement a popup with a slight delay. However, I am encountering issues where the buttons are not functioning properly without the delay, and they do not appear when I add the delay. I have come across information online mentioning that $ti ...

When working with Nuxt 3, the referrer header may sometimes return as undefined

I am looking to capture the referrer header and store it in a cookie so that I can later use it to populate an axios request during the user's journey on my website. In my app.vue, I currently have the following code snippet: const headers = useReque ...

Does GIF animation operate on the same thread as JavaScript in all popular web browsers?

When my AJAX request is in progress, an animated GIF is displayed to show activity. However, I have noticed that the animation freezes while the response from the request is being processed by a script that heavily updates the DOM. After researching this ...

Extracting information from AWS Amplify Graphql API

Graphql Schema : type Media @model { id: ID! title: String type: String } Sample Data : { id: "1234", title: "example image1", type: "image/jpeg", } { id: "5678", title: "ex ...

Having trouble loading CSS file in node js after submitting form

Before diving into more details, let me explain my current situation. I am utilizing node's nodemailer to facilitate the process of sending emails based on the information submitted through a form. Initially, everything was functioning smoothly when t ...

The incorrect sequence of Angular/Protractor functions is causing issues within the tests

Trying to extract the values from a column in a grid and compare them before and after sorting can be tricky. I have two functions set up for this task - one to retrieve the initial column values, and another to check the order post-sorting. However, there ...

Could somebody clarify the situation with the `push` function?

Something seems off with the behavior of the push method. Instead of pushing to only one index within the forEach, it appears to be pushing to all three indexes. Can anyone see what might be causing this unexpected result? let arrayToReduce = [ [ 1, 2, ...

Having trouble with the nav-item dropdown functionality on Laravel Vue?

Currently utilizing Laravel and Vue.js along with AdminLTE. Initially it was functioning properly, but now... head <!-- Font Awesome Icons --> <link rel="stylesheet" href="plugins/fontawesome-free/css/all.min.css"> <!-- Theme style --> ...