Adding a javascript file to a Vue component

I am currently working on a project that involves using Laravel and Vue.js. In order to incorporate an image editing package called "photojshop" into my Vue component, I tried the following approach:

<template>
<img src=".." id="myImg" >
</templete>


<script>
  import $ from 'jquery'
  export default {
    data: () => ({
      ......data of your component
    }),
    mounted() {
      let recaptchaScript = document.createElement('script')
      recaptchaScript.setAttribute('src', 'my local js file')
      document.head.appendChild(recaptchaScript)
    },
    methods: {
      EditImage(){
        $('myImg').photoJshop({ .... }) (error)
      }
    }
  }
</script>

However, when trying to execute the function $('..').photoJshop({}), I encountered an error stating that the function is not defined (photoJshop).

Answer №1

After some troubleshooting, I found the solution by implementing my code within

this.$nextTick(function () {
           ....
        })

and that did the trick!

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

Converting a floating point number to a 4-byte hex string in JavaScript and reversing the process

I have received a hexadecimal data from the server side that is supposed to be in float format. I am trying to convert these hexadecimals into floats using JavaScript, but so far I have been unable to find a suitable method. Can anyone provide assistance ...

Using JavaScript to send formatted text through POST requests in a Rails application

Within APP A, I have the following formatted text: A beautiful painting because I created it because an artist endorsed it because my cat loves it I can access this formatted text in index.html.erb through product.body_html, which I then load into a Ja ...

Iterate through the entire array without including a specific item

I am struggling with looping through an array of items and applying some code to each item while excluding one specific item (the clicked-on item). I have experimented with using splice, but that method ends up removing the array item completely, whereas I ...

Is it possible to sketch basic 2D shapes onto 3D models?

Is the technique called projective texture mapping? Are there any existing library methods that can be used to project basic 2D shapes, such as lines, onto a texture? I found an example in threejs that seems similar to what I'm looking for. I attempt ...

CSS or jQuery: Which is Better for Hiding/Showing a Div Within Another Div?

Show only class-A at the top of the page while hiding all other classes (x,x,c). Hide only class-A while showing all other classes (x,x,c). Is it possible to achieve this? <div class="x"> <div class="y"> <div class="z"&g ...

Get a CSV file through EmberJs

I have been experimenting with various function calls, but I am unable to figure out how to initiate a CSV download in EmberJs. Below is the most recent code I have tried: let endpoint = '/api/foo/'; let options = { url: endpoint, type: ...

initiating a submission upon the occurrence of an onchange event on an input field of type "file"

I have encountered an issue while trying to submit a form using the onchange event of an input element with type file. The problem is that it submits an empty form even when a file has been chosen. Here is the code snippet: var form = document.createElem ...

How long does it take to delete and recreate a cloudfront distribution using AWS CDK?

I am currently undergoing the process of migrating from the AWS CDK CloudfrontWebDistribution construct to the Distribution Construct. According to the documentation, the CDK will delete and recreate the distribution. I am curious about the total duration ...

Personalized date range filter

I've been attempting to narrow down the data based on two specific dates, but I seem to be having trouble getting it to work correctly. Is there anyone out there who can lend a hand? Here is my HTML: <input type="date" ng-model="from_date"> &l ...

VueD3tree successfully fetches data, however, it is not being displayed on the screen

Just started delving into Vue and VueD3tree. Attempting to display a tree using the vued3tree library with data pulled from an API. Strangely enough, when trying with static data, the tree displays perfectly fine. However, when fetching data dynamically, a ...

Using jQuery to clear a textarea when a select input is changed

Currently, I am in the process of developing a small text editor that enables users to edit files and create new ones. Here is how I have set up my select menu. <select name="reportname" id="reportname" class="form-control"> <option value="zr ...

Incorporate Javascript to smoothly transition a div into view, display it for a specified duration, gradually fade it out, and ultimately delete

I am excited to experiment with toast notifications by creating them dynamically. Each toast has a unique id number and I increment a counter every time a new one is created. The current functionality includes the toast sliding down, staying visible for 3 ...

How to extract data from a child component in Vue.js

This component called LoggedUser is responsible for displaying the name of the logged-in user and their scope. The user's name will be shown in the sidebar, and the scope will determine which countries are displayed under the user's jurisdiction. ...

Tips for utilizing the 'primary' parameter in package.json?

After conducting extensive research, I still find myself uncertain about the purpose of the 'main' parameter in a Node project's package.json file. How does filling in this field benefit the project? In other words, can the module be initia ...

The execution of the function halts as soon as the player emerges victorious

In my attempt to create a basic game where players compete to click their designated button faster to reach 100%, I am in need of assistance with implementing a logic that determines the winner once one player reaches or exceeds 100. Essentially, I want ...

Having trouble accessing the value of a node in JavaScript, as it keeps returning as "null"

Experimenting with converting HTML elements into lists. The objective is to generate a list of all values in a table upon clicking the "page next" buttons on it. Afterward, an alert should display the value of the first item in the list, which corresponds ...

I'm puzzled as to why I keep receiving unexpected months despite utilizing the BETWEEN method in my query

It just dawned on me that I mistakenly posted the wrong code for my question earlier Despite setting the BETWEEN method in my statement, I am still getting random months when trying to run it in my nodejs with mysql2. Why is that happening? SELECT u.d ...

Securing API routes in Laravel

I have a Laravel application integrated with VUEJS for the front-end. I am retrieving data through API Routes. As an example, the route to fetch posts data is http://localhost/api/posts What would be the most effective method to secure my routes? After r ...

A guide on implementing a Keycloak Login theme with Vuetify

As a newcomer to web development, I may have some fundamental misunderstandings. The Goal: We are utilizing Keycloak for access management in our web application. The application is a Vue project using Vuetify. In order to maintain a consistent visual des ...

Is it possible to combine JavaScript objects using TypeScript?

Currently, I am dealing with two objects: First Object - A { key1 : 'key1', key2 : 'key2' } Second Object - B { key1 : 'override a' } I am looking to combine them to create the following result: The Merged Re ...