question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

use :list with computed prop

See original GitHub issue

already saw https://github.com/SortableJS/Vue.Draggable/issues/52 but i have a slightly diff example, check https://codepen.io/ctf0/pen/BwLezW

when using colorsList as computed prop, i can omit the watchers, mounted() and make the code much cleaner, so when trying to drag while using computed, only the first item gets dragged , but from second item on i get an error that computed prop doesnt have a setter.

i thought i could use the computed prop for v-model and use :list with some other empty array, so now the sorting can be cloned and saved into this new array, but that didnt work.

so is there anyway to use computed prop with :list ?

on a side note

when releasing a dragged item, there is a quick flicker of the old in-place item, try to re-sort the bubbles in the example and watch what happens for the colors b4 the sort gets applied.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
David-Desmaisonscommented, Oct 6, 2017

@phaberest as mentioned in this issua as well as in #52 , computed is not supported and could not be supported use provided work-around instead.

0reactions
phaberestcommented, Oct 11, 2017

I just needed to change the data in the main object when saving. Using :list for my computed and v-model for my original non filtered object works fine.

If anyone ever need it, this is what I did: (shownStages is my computed)

// This is a little tricky. If the shown stages are filtered, we
// can't update their order since they come from a computed, but
// we instead have to check their indexes on the real object and
// swap them.
if (this.shownStages.length != this.pipeline.stages.length) {
    let stagescopy = this.pipeline.stages;
    let changed    = [];
    _.forEach(this.shownStages, (stage, index) => {
        // Get the real indexes
        let real_index = _.findIndex(stagescopy, {
            id: this.sortedStages[index].id
        });
        let other_index = _.findIndex(stagescopy, {
            id: stage.id
        });

        // Check if we swapped them already.
        if (_.includes(changed, other_index)) {
            return false;
        }

        // Swap the elements
        let swapped = stagescopy[other_index];
        stagescopy[other_index] = stagescopy[real_index];
        stagescopy[real_index] = swapped;

        // Note the index we changed so we don't swap them again
        changed.push(other_index);
    });
    this.$set(this.pipeline.stages, stagescopy);
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Computed Properties - Vue.js
You can data-bind to computed properties in templates just like a normal property. Vue is aware that this.publishedBooksMessage depends on this.author.books , ...
Read more >
Filtering List Using Computed Properties in VueJS - 5 Balloons
Problem: We want to filter a list by user input using Computed Properties in VueJS. Solution: We'll solve this using multiple examples and ......
Read more >
Vue JS - Loop through a computed property to display a list of ...
I currently have the following code that lists a ...
Read more >
How to use computed properties in Vue, with examples.
All the computed property is doing is checking that there is at least 1 in the user's array, the computed prop will update...
Read more >
Using Vue computed properties - Learn web development
Add the following code to your App component object, below the methods property. The list summary method will get the number of finished ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found