Beginner's guide to integrating the @jsplumb/browser-ui into your Vuejs/Nuxtjs project

I am working on the integration of @jsplumb/browser-ui community edition into my application. After receiving a recommendation from the team at jsplumb, I decided to utilize @jsplumb/browser-ui. However, I am facing difficulty in understanding how to begin integrating it into my Vue/Nuxtjs application.

Here are the steps I have been following:

  1. Install @jsplumb/browser-ui using
    npm install @jsplumb/browser-ui --save
    .
  2. Add the libraries to the nuxt-config.js under the script section:
script: [
      {
        src:"node_modules/@jsplumb/core/js/jsplumb.core.umd.js",
        mode: 'client'
      },
      {
        src:"node_modules/@jsplumb/browser-ui/js/jsplumb.browser-ui.umd.js",
        mode: 'client'
      }
    ]
  1. The code snippet I have so far is:
<template>
  <div class="row">
    <div class="col-md-12">
      <div id="diagram" style="position: relative" />
    </div>
  </div>
</template>

<script>
if (process.browser) {
  const jsPlumbBrowserUI = require('node_modules/@jsplumb/browser-ui/js/jsplumb.browser-ui.umd.js')
  const instance = jsPlumbBrowserUI.newInstance({
    container: document.getElementById('diagram')
  })
  console.log(instance)
}

export default {
  mounted () {
    if (process.browser) {
      console.log('MOUNTED BLOCK')
    }
  }
}
</script>

I am encountering difficulties in the integration process within my application. The available documentation does not present a comprehensive example specific to Vue/Nuxtjs

Answer №1

By incorporating dynamic imports, as demonstrated in this preceding response, and exclusively importing the jsplumb package within a browser environment, the problem encountered by the original poster was successfully resolved.

In addition to utilizing $refs for accessing child component instances and elements.

Answer №2

Here is the solution that worked for me after taking into account suggestions from @kissu:

<template>
  <div class="row">
    <div class="col-md-12">
      <div id="diagram" ref="diagram" style="position: relative" />
    </div>
  </div>
</template>

<script>
export default {
  async mounted () {
    if (process.browser) {
      const jsPlumbBrowserUI = await import('@jsplumb/browser-ui')

      const instance = jsPlumbBrowserUI.newInstance({
        container: this.$refs.diagram
      })
      console.log(instance)
    }
  }
}
</script>

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

Confirmation checkbox that retains original value if canceled

Imagine a scenario where there is a checkbox value. When the checkbox value changes, the user is asked, "Do you want to SHOW this item on the website?" or "Do you want to HIDE this item on the website?" Everything seems to be working fine, except for one ...

Ways to ensure that a function completes in an Express route

I currently have a route set up like this: app.get("/api/current_user", (req, res) => { //It takes about 3 seconds for this function to complete someObj.logOn(data => { someObj.setData(data); }); //This will return before ...

Increased/Decreased impact

Can someone explain how the "Tell me more" effect is achieved on the website linked below? I'm familiar with the read more/less effect in jQuery, but what intrigues me is that the page cannot be scrolled unless the button is clicked. Here is the link ...

Is it achievable to delete certain content post window launch in Nuxt.js?

<template> <div> <Ccomponent /> <Dcomponent /> <div @click="openWindow()">hello</div> </div> </template> <script> export default { data() { return ...

Tips on implementing jQuery in a JavaScript file referenced in angular.json

Currently, I am utilizing a JavaScript file that incorporates jQuery within it. In order to employ this JavaScript file, I have included it in the scripts array within the angular.json file. Additionally, I have also included jQuery in the same array befor ...

What is the purpose of assigning controller variables to "this" in AngularJS?

Currently, I am analyzing an example in CodeSchool's "Staying Sharp with Angular" course in section 1.5. Here is the code snippet: angular.module('NoteWrangler') .controller('NotesIndexController', function($http) { var contro ...

Typescript - Creating a Class with Constructor that Extends an Interface without Constructor

I am faced with an interface structured as follows: interface Person { id: number name: string } In my implementation class for this interface, I have the following code: class PersonClass implements Person { id: number = 123 name: string = &apo ...

Encountering an unanticipated reference error while attempting to paste the data

// Modify the layout function document.addEventListener('DOMContentLoaded', function() { function modifyLayout(productId) { // Referencing the original card and detailed card const originalCard = document.querySelector(&ap ...

Any ideas for handling ProtractorJS timeouts while clicking an element?

The Issue at Hand I am currently facing a challenge with clicking a straightforward 'New Booking' button in my Angular 5 Material 2 Application. The code snippet for the button is as follows: <button _ngcontent-c9="" class="mat-menu-item" ma ...

Issue with dynamic imports in express routes

I am currently attempting to incorporate a dynamic import within an express.js router Here is the code snippet I have: HelloWorldController.js export const helloWorld = function (req, res) { res.send('hello world') } router.js export defa ...

JavaScript Button with the Ability to Input Text in a TextArea?

For instance, imagine a scenario where you click on a button and it then displays various options for you to select from. Whatever option you pick will be automatically inserted into the text area. ...

The file type stored in Firebase storage is identified as 'octet-stream' rather than the expected 'png/jpg' format

I am experiencing an issue with uploading images to Firebase storage. After uploading them, I notice that they are labeled as application/octet-stream instead of the expected types like image/jpeg or image/png. Below is the code snippet I am using: <in ...

What is the best way to maintain the index of a for loop when incorporating AJAX to insert PHP data into an object?

Hey there, I'm diving into the world of AJAX and PHP implementation. I've hit a bit of a roadblock lately as I feel like I might be missing a simple solution. Currently, my code fetches data from a trove API using PHP, and for each item it appen ...

How can nextJS leverage async getInitialProps() method in combination with AWS S3?

I'm currently facing a challenge with executing an s3.getObject() function within an async getInitialProps() method in a nextJS project. I'm struggling to properly format the results so that they can be returned as an object, which is essential f ...

Issue with React component not receiving dataThe values are not being

Currently, I am a beginner in using React and as part of my training, I have embarked on a project to create a simple book ranking system. In this project, the user enters the title of the book they would like to vote for. If the input field is left empty, ...

I am looking to modify the highlighted table cell whenever the value within it changes

I am currently working on a small project related to the Stock Market. In this project, I need to dynamically change the style of the td element based on data fluctuations - green highlight for an increase and red highlight for a decrease. In the provid ...

What is the best way to synchronize the state of a single React component across various pages?

I am currently working on a React Component that includes a toggle feature (on or off) with the state being managed by the component's own state (this.state). My dilemma is ensuring that this state remains when the user navigates from one page to ano ...

Having difficulty accessing information from Firebase database using the .once() function

When a button is clicked on the page, I need to fetch data from a Firebase database using the once() function. Despite setting up the necessary references and variables, the data retrieval seems to be unsuccessful as the global variable numElections keeps ...

The error message "TypeError: Unable to access property 'path' of an undefined variable" appeared during the upload of

Recently, I encountered an issue while trying to add a product with an image to mongoDB. While my Postman tests are successful, I'm facing an error when attempting to do it from the frontend – it says "cannot read property path." I believe there&apo ...

How to show dates in AngularJS using local formatting

One situation I'm dealing with involves setting a date for an event. The challenge is that the date picker needs to display the date in a localized format based on the country or region. I've been exploring various solutions in AngularJS, but so ...