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.

Update X,Y from component method

See original GitHub issue

Hi, I’ve the next code:

<button @click="InitPosition()">blla</button>
<vue-draggable-resizable
  v-if="DrillSelectorView"
  :parent="true"
  :x="testPosition['left']"
  :y="testPosition['top']"
  :w="460"
  :h="245"
  @dragstop="onDragstopDrillSelector"
  >
  <drill-selector/>
</vue-draggable-resizable>
data: () => ({
  testPosition: {
    left: 0,
    top: 684
  },
}),
mounted() {
  this.InitPosition();
},
beforeUpdate() {
  this.InitPosition();
},

initPosition: function() {
  this.testPosition= {
    left: 747,
    top: 1000
    };
}

Not the button or the beforeUpdate hook in working, only the mounted hook is working.

How should I update the init x,y location? Thank you

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
TitanFightercommented, Jul 25, 2019

@liquidvisual In your code when you drag, positions (x, y) do not change. Add x: {{ x }}, y: {{ y }} and you will see it. In order to fix it, you need @dragging="onDrag"

<template>
  <div id="app" :style="windowStyle">
    <button @click="resetPosition">reset x,y</button>

    x: {{ x }}, y: {{ y }}

    <vue-draggable-resizable class-name="test-class"
      :parent="true" :x="x" :y="y" :w="260" :h="145" @dragging="onDrag">
      <p>Drag me away then click reset (nothing happens)</p>
    </vue-draggable-resizable>
  </div>
</template>

<script>
import VueDraggableResizable from "vue-draggable-resizable";

export default {
  name: "App",
  data: function () {
    return {
      x: 0,
      y: 0,

      windowStyle: {
        height: "884px",
        width: "1207px",
        position: "relative"
      }
    }
  },
  components: {
    VueDraggableResizable
  },
  methods: {
    resetPosition: function() {
      this.x = 0;
      this.y = 0;
    },
    onDrag(left, top) {
      this.x = left
      this.y = top
    }
  }
};
</script>

<style>
#app {
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
.test-class {
  border: 1px solid black;
}
</style>
1reaction
mauriciuscommented, Jul 26, 2019

Thanks @TitanFighter, as always you’re definitely more helpful than me 😂

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get a reference to component at specific x,y ...
measure is react native default method for any component to get update on it. Below is the example which help you to get...
Read more >
XY Graph, initialize multiple sets of data, and update only one ...
At this point, my motors are moving dreadfully slowly, and I'm trying to find a way to make them run faster. I am...
Read more >
Using React – amCharts 4 Documentation
If you want to update the chart, you can use the componentDidUpdate method. Here is an example: TypeScript / ES6 ... class App...
Read more >
Component QML Type | Qt QML 6.4.1
In the same way, a Component definition contains a single top level item ... For example, the code below creates an object with...
Read more >
d3/d3-selection: Transform the DOM by selecting elements ...
This method is used internally by selection.join to merge the enter and update selections after binding data. You can also merge explicitly, although...
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