Utilizing a JavaScript library causes this error of "undefined"

I have been experimenting with different variations, but I am unable to understand why I am facing difficulty in including the library: jkanban.js

<template>
  <div id="kanban"></div>
</template>

<script>

import jKanban from '../components/jkanban.js'

export default {

}

</script>

The error message displayed in the console is:

Cannot set property 'jKanban' of undefined

Upon closer inspection, I noticed that this is actually undefined.

This code works perfectly fine without Vue.js, and I am unsure about what might be causing the issue.

Internally, the library operates as follows:

(function () {

    this.jKanban = function () {
        var self = this;
...

Answer №1

Here is how I integrated jKanban into my Vue 3 project, but this method should also work for React or older versions of Vue...

To begin, navigate to the source code repository at https://github.com/riktar/jkanban and make sure to only copy the jkanban.js file from the root directory (avoid copying from the dist folder which contains unnecessary files related to the dragula library). Paste this file into a designated folder within your own project.

Next, install the dragula library using the command: npm install dragula.

There were some necessary code modifications that had to be made. For instance, I encountered issues with the dragula library due to the absence of a global object, so I included the line: const gobal = window; either in the index.html file or another suitable location.

I also made amendments to the jKanban.js file. Initially, I updated the import statement to use ES6 syntax instead of require:

import dragula from "dragula";  // change from require

const jKanban = function () {
    var self = this
    var __DEFAULT_ITEM_HANDLE_OPTIONS = {
   // etc. etc...

Lastly, towards the end of the file:

    //init plugin
    this.init()
}

export default jKanban; // export it

After making these adjustments, I successfully imported and utilized jKanban within one of my components as shown below:

import jKanban from "@/stuff/jkanban.js";
// ...stuff
const kanban = new jKanban(someOptionsIPreparedEarlier);

Remember to include the corresponding CSS file and manually update the library whenever needed.

:o)

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

Is there a way to determine when an animation finishes in Vue Nativescript?

Vue Nativescript does not support the v-on hook, even though I found a solution for VueJS. Check out the solution here Currently, I am applying a class to trigger an animation: Template <Image ref="Image" :class="{scaleOut: scaleOutIsActive}" ...

useEffect does not trigger a rerender on the primary parent component

I am facing an issue where the main parent component does not re-render when I change the state 'click button' in another component while using useEffect. Oddly enough, the main <App /> component only re-renders properly when I reload the p ...

Adding elements to my state array - Utilizing Nextjs/React/Javascript

After fetching data from 2 different APIs that each return an object, I have stored them in separate states. Now, I want to merge these two objects into a single state that contains both of them as an array. However, when I try to do this, the second obj ...

Struggling to decide on the perfect CSS selector for my puppeteer script

I am trying to use puppeteer page.type with a CSS selector. <div class="preloader"> <div class="cssload-speeding-wheel"></div> </div> <section id="wrapper" class="login-register"> <div class="login-box"> <d ...

The length of the scope variable generates an error

var example = $scope.newgoal.gTitle; console.log(example.length); Even running this short code test, it throws an error message: TypeError: Cannot read property 'length' of undefined I've attempted to find various solutions without succes ...

Creating a modal window when a link is clicked in an MVC application

I am looking to open a Crystal Report in a pop-up window when a menu item is clicked. <%= Html.ActionLink("Display Name", "Action","Controller", new { target="blank"})%> The code above successfully opens the report, but it currently opens in a new ...

I encountered a 'Reference Error: button is not defined' issue

Exploring the concept of 'Closure' and experimenting with this sample code. Testing it out in Visual Studio Code. for (let [idx,btn] of buttons.entries()) { btn.addEventListener( "click", function onClick(){ con ...

Creating these three functions directly in the Parent Component instead of duplicating code in the child component - ReactJS

I am new to React and currently working on a dashboard page that includes a React Table. The page features a customize button that opens a popup with checkboxes to show/hide columns in the table. By default, all checkboxes are checked but unchecking a colu ...

When clicking on a name in the leaderboard, receive comprehensive information in a separate window or a popup

I have a unique leaderboard setup here featuring four JavaScript tabs that showcase different leaderboards when clicked. To run the code snippet, please see below: $(document).ready(function() { $('.tab a').on('click', function(e) ...

Creating interactive Vue components using sync and event handling

In my Vue.js 2.3 project, I am dynamically rendering a list of components using <component v-for="..."> tags. The structure of my template is as follows: <some-component v-for="{name, props}, index in modules" :key="index"> <component ...

"Immersive Virtual Reality Experience with Curved Plane and Interactive Text in

While the Aframe API already supports curved images, I'm interested in creating curved text and planes as well. Can anyone provide guidance on how to achieve this? I believe I need to create an entity for this purpose, but I am unsure about which pro ...

Submitting a form in Codeigniter with AJAX causes unnecessary posts due to the presence of a jQuery cookie

Having an issue with the $.cookie jQuery plugin causing my form to submit prematurely. The form code is as follows: <?php echo form_open($this->uri->uri_string(), 'class="ajax_email_submission"'); ?> <div id="email_new ...

Creating multiple versions of a website based on the user's location can be achieved by implementing geotargeting techniques

It may be a bit challenging to convey this idea clearly. I am interested in creating distinct home pages based on the source from which visitors arrive. For instance, if they come from FaceBook, I envision a tailored home page for FaceBook users. If they ...

Ways to pass a message from index.html to a Vue.js 3 instance

Picture this scenario: You have a Vue index.html file that also loads a custom script: <!DOCTYPE html> <html lang="en"> <head> ... ... <script type="text/javascript"> languagePluginLoader.then(fun ...

I have a JSON file saved on my desktop that I would like to incorporate into my JavaScript code. Any suggestions on how to efficiently achieve this integration

Here is a code snippet that I have been experimenting with: const dictionary = require('dictionary.json'); //(with file path) console.log(dictionary); ...

Utilize D3's pie chart to showcase the data in JSON's individual collections

I am currently working on creating a pie chart that displays the distribution of collections based on their names. I have come across an issue where d3.layout.pie().value() only evaluates specified array values. Is there a solution available to extract the ...

In Phaser 3 JavaScript, I observed two objects in the display, both overlapping each other, yet no events were triggered

My goal is to make the coin disappear when the player overlaps with it. However, for some reason, the cutcoin function is not being called and I'm not sure why. function create() { var healthGroup = this.physics.add.staticGroup({ key: &ap ...

What mistake am I making that is preventing me from gaining access to object properties?

I've encountered an issue that has me stumped. The task at hand is as follows: Create an onload event handler named init() In init(), generate 3 JavaScript objects, each containing the same 6 properties (with Price being key) Set the initial values ...

send a message to all clients using socket.io

I am having trouble figuring out how to broadcast a message from the client or another NodeJS file to all clients. While I was able to send messages to the server successfully, I am not able to reach every other client. Server code: var io = require(&ap ...

Encountered an error: Object(...) does not conform to function standards in the handleChange method

When using JavaScript, everything works fine. However, when trying to implement TypeScript with the handleChange function, an error is consistently thrown whenever something is typed into the entries. The error message reads: "TypeError not captured: Objec ...