Using GridStack in combination with VUE causes issues with reactivity

I'm struggling with adding VUE components to a GridStack because they aren't reacting properly.

Check out the issue in this CodePen: https://codepen.io/adelriosantiago/pen/qBaXjrr?editors=1010

Since GridStack only accepts HTML, my workaround involves creating a new Vue instance using

let instance = new gridStackItem();
and then mounting it with instance.$mount(); to access the compiled HTML in instance.$el.

After that, I use addWidget following GridStack's documentation. The added elements appear correctly (you can see "SUBTEXT" text) but unfortunately, these components are not reactive, as indicated by the inability to change their text via the input field (refer to image below).

https://i.sstatic.net/g170L.png

What steps should I take to make these components reactive?

Answer №1

The creation of a new div element was successful.

let item = new gridStackItem();
      
let newDiv = document.createElement('div');
newDiv.id = Math.random().toString(24).substring(8) // setting an id for future access
      
item.$mount(newDiv);

Next, insert the newly created div as content in your addWidget.

let widget = this.grid.addWidget({
  x: Math.round(Math.random() * 5),
  y: Math.round(Math.random() * 5),
  w: 4,
  h: 2,
  content: newDiv.outerHTML
});

Subsequently, add your component instance as a child of the div.

document.getElementById(newDiv.id).appendChild(item.$el)

This approach proved to be effective! Using the div as a connection point between the widget and instance was the key. See the updated version on Codepen

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

Retrieve facet queries in JSON format from Solr using JavaScript

Utilizing Solr facets to categorize queried documents by both their category and published date has proven successful. With a query that outputs the desired results in JSON format, the outcome resembles: "facet_counts":{ "facet_queries":{ "pub ...

A gathering focused on the pause function of a bootstrap carousel

After carefully reviewing the documentation, it seems there isn't a specific event to detect when the carousel is paused. Is there a workaround for detecting when the bootstrap carousel is paused? The carousel can be paused using various methods, and ...

Listening to multiple events in AngularJS using `$scope.$on`

I am faced with a situation where I need to respond to two different events being transmitted via $scope.$emit and take action only when both have occurred. For example, if the events are triggered in the following sequence: $scope.$emit('first&apos ...

adding a variable to the value of an input field using the val() method

Here is a code snippet that appends the text 'text goes here' to an input value: $('#someid').val($('#someid').val() + 'text goes here'); I attempted to use a variable in a similar way, but it didn't work as e ...

Socket.io connects two clients together in a room

Currently, I am working on integrating private messaging functionality into an app I am developing using express 3 and socket.io. Upon a client connection, a room is automatically created and joined based on the client's user id. This feature serves ...

When I try to post using the raw feature in Postman in Node.js, the post ends up empty

My API is supposed to receive data for saving in the database. However, when I call the PUT method, my req.body.nome returns empty. It works fine with form-urlencoded, but I've tried using body-parser and it's deprecated. Here is my request usin ...

Creating a simulation of a JavaScript callback within a C# host program

Currently, I am in the process of developing a c# application with an embedded web browser control. In this project, I'm facing a challenge where I need to call a C# method from JavaScript and pass a JavaScript callback using the dynamic technique exp ...

Utilizing @Material-UI Tabs for a Stylish Navigation Bar

As a newcomer to the coding realm, I find myself on a quest for an answer that has proven elusive. Despite scouring various sources, none of the solutions I've stumbled upon seem to work in my case. The issue at hand revolves around my desire to util ...

qunit timer reset

I have developed a user interface for manually launching qunit tests. However, I have noticed that the qunit test timer starts when displaying the interface, rather than when starting the actual test. For example: var myFunction = function (){ test ...

Updating a connected model in Sequelize using another model

Seeking guidance on updating a model with new associations in Sequelize. The model involves a many-to-many relationship with a join table. Attempted this code snippet: app.patch('/api/team/:id/newplayers', function(request, response){ const pl ...

Exploring the concept of module patterns in JavaScript

Currently, I am working on honing my JavaScript skills as I am relatively new to the language. I am attempting to identify the specific element that triggered an event and display it within a span element. However, I seem to encounter an issue as clicking ...

Matching URLs with wildcards in a Chrome Extension using Javascript

I am developing a Chrome extension that enables users to customize content on specific websites. I want to allow users to specify these websites using wildcards, like http://*.google.com or http://google.com/* While researching, I came across the followin ...

The error message states: "Dygraph is not defined."

Currently, I am utilizing express.js in my application to render dygraph charts on the client side. You can take a look at my index.jade file here. Upon visiting my browser, an error pops up in the console: Uncaught ReferenceError: Dygraph is not defined. ...

Vue Router unexpectedly triggers two URL updates when a single push() call is made

When using this.$router.push({ path: '/upload'});, the browser URL is updated to ...#/upload just fine. However, when utilizing this.$router.push( '/edit/file/4' );, the expected URL briefly flashes in the address bar before being updat ...

Unable to retrieve uploaded files within the controller

Update with the latest code that helps solve my problem $scope.uploadedFiles = []; $scope.upload = function(files) { $scope.uploadedFiles = files; angular.forEach(files, function(file) { if (file && !file.$error) { ...

Tips on implementing {% csrf_token %} with javascript

On my users page, I have implemented editing with ajax. Initially, the edit function works fine but upon submitting the form, nothing happens. The error message revealed that: CSRF verification failed. Request aborted. Could someone guide me on how to in ...

What is the best way to simulate this function in a jest test for a react component?

Within my testing suite for Jest, I encountered the following scenario: it('should render Alerts', () => { const component = withTheme( <AlertsContainer alerts={alertsMock} getApplicants={applicantsMock} /> ); const wrapper = shallow(co ...

Retrieve the element from the most recent append() function invocation

Is it possible to change the chain context to a new DOM node when using append() to insert it? Here is an example code snippet demonstrating this: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org ...

Sharing data from a Provider to a function in React can be done through various methods

After developing an NPM library that contains various utility functions, including one for calling endpoints, I encountered a roadblock when trying to set the Axios.create instance globally. Initially, my idea was to create a Provider and establish a cont ...

Comparing two jQuery methods for looping through Ajax requests - which one is the best option?

Currently working on a blog project that involves integrating Isotope Jquery (for layout/filtering/sorting), Infinite Scroll, and dynamic loading of all blog excerpts via Ajax. The goal is to apply filtering and sorting to all excerpts before they are load ...