Incorporating VueJS components dynamically into Packery: A step-by-step guide

Hey, I'm encountering an issue with packery.

I have each grid-item as a component and in my app.js (main file) I'm initializing packery following this example https://codepen.io/Monocle/pen/ZbeBGL

  var pckry = new Packery(container, {
    itemSelector: '.grid-item',
    columnWidth: '.grid-sizer',
  });

My goal is to control turning on/off components, making them draggable, and binding/unbinding them to packery. However, I'm struggling with adding packery as an attribute of the Vue object so that I can use this.pckry.getShiftPositions() just like in this example: https://codepen.io/desandro/pen/PZrXVv.

pckry.on( 'dragItemPositioned', function() {
  // save drag positions
  var positions = pckry.getShiftPositions( 'data-item-id' );
  localStorage.setItem( 'dragPositions', JSON.stringify( positions ) );
});

The issue seems to be with handling the instance of the packery object. It's just not functioning correctly.

this.pckry.on( 'dragItemPositioned', function() {
  // save drag positions
  var positions = this.pckry.getShiftPositions( 'data-item-id' );
  localStorage.setItem( 'dragPositions', JSON.stringify( positions ) );
});

But it doesn't actually work. When I try to do it like this:

this.pckry = newPackery(...);

How can I effectively address this issue?

Answer №1

Ever since I started using the packery library, it feels like ages have passed. Each time I added something to the grid, I had to recreate the packery instance, only to find that it was re-sorting everything again. The sorting is based on one dimension, like a list, which doesn't quite meet my expectations. I needed to store the (x,y) positions for all grid items.

Furthermore, Vue Virtual DOM and jQuery DOM operate differently and don't seem to align well together. It's not common practice to use them in conjunction, as far as I can tell.

As of now, I'm developing my own grid layout for VueJS and making some final tweaks. Feel free to follow my progress here: https://github.com/lrembacz/vue-responsive-grid-layout

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

When a user clicks, they will be directed to the specific product page using Angular UI router

On my homepage, I have a JSON feed where all the products are displayed. When clicking on a specific product image, I want it to redirect to a separate page showing only that particular product. I understand that changes need to be made in the singleproduc ...

How can I display a JSON object in HTML using code?

I have implemented the following code snippet: js jQuery.getJSON("https://en.wikipedia.org/w/api.php?action=query&list=embeddedin&eititle=Template:Infobox&eilimit=5&callback=?", { disablelimitreport: true, format: "json" }, fu ...

Utilize generated styling data bindings when referencing assets

Currently, I am working with vue-cli 3 and trying to create background-image paths. To achieve this, I am utilizing the style data bind within a v-for-loop. Below is the component structure: <template> <ul> <li v-for="(tool, inde ...

Initializing start scripts in the package.json file

When launching my react app locally, I need to execute three commands: cd react-web npm run postinstall export REACT_APP_CUSTOMER_ENVIRONMENT=xxx npm start After running these commands, the application server starts on localhost:3000. For the start script ...

Creating paths with parameters in VueJS the right way

Currently, while following a tutorial, I am encountering an issue where the paths with parameters are not functioning properly. data() { return { id: this.$route.params.id, element: { title: '', descri ...

The issue with Nuxt 3 page transitions not functioning as expected seems to be

Exploring the possibilities of Nuxt 3, I am eager to implement animated transitions between pages using JavaScript hooks and libraries like gsap or animeJs. In my app.vue file, I have simply placed <NuxtPage/> inside a <Transition> element as ...

Guide on utilizing isElementPresent/isPresent within ng-repeat with Protractor

HTML Code: <div ng-repeat="todo in todos"> <span><input ng-model="todo.title" /></span> <span><input ng-model="todo.time" /></span> <span><input ng-model="todo.name" /></span ...

In Reactjs, Axios and fetch are both commonly used for sending ongoing network requests to localhost

In order to establish a successful connection between the express backend and MongoDB database, I initially used fetch("/") from the frontend, which returned the index.html code. However, when I switched to fetch("http://localhost:9000"), I encountered a C ...

Glitched Water Reflection in THREE.js

Creating a water scene using JavaScript. I followed the official examples to set up the scene, but the reflection seems off after loading an external GLTF model. Initially everything looks fine, but once I start moving the camera, things go awry. I suspe ...

Identify the points of intersection between two numpy arrays in Python

Consider the following two arrays: x, y = np.array([13., 14., 15., 32., 33.]), np.array([15., 16., 17., 33., 34., 47.]) The goal is to determine the indices of elements in x that do not appear in y. For instance, based on the example given above, the out ...

Utilizing the Vue feature of dynamic route naming within a component's function

Currently, I am working on creating a dynamic view rendering using Vue and Laravel. However, I am facing difficulty in understanding how to pass the dynamic parameter to the component function. Router.map({ '/cms-admin/:page': { comp ...

The positioning of CSS arrows using the "top" attribute is not relative to the top of the page when using absolute values

I am currently working on positioning the arrow in the screenshot using TypeScript calculations. However, I am facing an issue where the position is being determined based on the top of the black popup instead of the top of the screen. From the top of the ...

Instant Pay Now Option for Your WordPress Website with PayFast Integration

I have encountered an interesting challenge that I would like some guidance on. My goal is to integrate a PayFast "Pay Now" button into a Wordpress.com blog, specifically within a sidebar text widget. The tricky part is that I need the customer to input th ...

Validation of the hidden subcategory field using jQuery is essential

I am struggling with implementing jQuery validation on a form that includes fields for title, category, subcategory, and message. While I have successfully added validation for all fields except subcategory, it just won't seem to work. I could really ...

Hide only the table that is being clicked on, not all tables

Essentially, I am using document.querySelectorAll() to retrieve an array of div elements. In my function, handleClick(), each time the button is clicked, I want to hide the table associated with that specific button. This is the current situation: https:/ ...

Querying a collection with a bulk request using Mongoose Cursor

My current challenge involves working with rxJS and handling bulk HTTP requests from a database containing over 1 million documents. The code I have is relatively simple. I am pushing all the documents from the collection into an array called "allPlayers" ...

What is the best way to conceal a div in React using components?

Below is the code I have for my App: import React, {Component} from 'react'; import App1 from './App1'; class App extends Component { render(){ return ( <> <App1/> ...

What is the reason behind the android code being incompatible with IOS operating systems?

I'm encountering an issue where a particular code is working on Android, but not on IOS. The code in question involves using JavaScript to differentiate the items in a list within an HTML select tag. It's perplexing to me how the code can operat ...

Track the number of clicks on the pop-up registered in the PHPMyAdmin database

There seems to be an issue with the IP not appearing in the other table within the same database. On the page "recette1.php?id=1" <?php $bdd = new PDO('mysql:host=localhost;dbname=recettes', 'root', 'root'); include("C:/ ...

Phonegap and the Importance of HTTP Requests

Having an unusual issue with Phonegap where my XMLHttpRequests are firing twice. Currently, I am working on an app that involves using XMLHttpRequests to generate a dynamic list of events for users to choose from. In addition to this, I am utilizing jQuery ...