#html #vue.js #vuejs2
#HTML #vue.js #vuejs2
Вопрос:
Это моя функция handleMove, которая в основном работает как
<div class="container" @mousemove="handleMove"></div>
Я хочу передать несколько функций, где у меня выделено жирным шрифтом в коде, проблема в том, что когда я делаю это.moveSelectedNode (diffX, diffY) другой
это.moveSelectedDecision не работает
Проблема в том, что один узел переходит в this.moveSelectedDecision и наоборот для решений
когда я комментирую одно, это другое, это работает нормально
Когда я комментирую один this.moveSelectedNode или this.moveSelectedDecision, другой работает нормально
handleMove(e) {
if (this.action.linking) {
[this.mouse.x, this.mouse.y] = getMousePosition(this.$el, e);
[this.draggingLink.mx, this.draggingLink.my] = [this.mouse.x, this.mouse.y];
}
if (this.action.dragging) {
this.mouse.x = e.pageX || e.clientX document.documentElement.scrollLeft
this.mouse.y = e.pageY || e.clientY document.documentElement.scrollTop
let diffX = this.mouse.x - this.mouse.lastX;
let diffY = this.mouse.y - this.mouse.lastY;
this.mouse.lastX = this.mouse.x;
this.mouse.lastY = this.mouse.y;
this.moveSelectedNode(diffX, diffY);
**this.moveSelectedDecision(diffX,diffY);**
console.log('I am here');
}
if (this.action.scrolling) {
[this.mouse.x, this.mouse.y] = getMousePosition(this.$el, e);
let diffX = this.mouse.x - this.mouse.lastX;
let diffY = this.mouse.y - this.mouse.lastY;
this.mouse.lastX = this.mouse.x;
this.mouse.lastY = this.mouse.y;
this.scene.centerX = diffX;
this.scene.centerY = diffY;
// this.hasDragged = true
}
},
Это мои функции moveSelectedNode и moveSelectedDecision, которые я передаю в handleMove
moveSelectedNode(dx, dy) {
let index = this.scene.nodes.findIndex((item) => {
return item.id === this.action.dragging
})
let left = this.scene.nodes[index].x dx / this.scene.scale;
let top = this.scene.nodes[index].y dy / this.scene.scale;
this.$set(this.scene.nodes, index, Object.assign(this.scene.nodes[index], {
x: left,
y: top,
}));
},
moveSelectedDecision(dx, dy) {
let index = this.scene.decisions.findIndex((item) => {
return item.id === this.action.dragging
})
let left = this.scene.decisions[index].x dx / this.scene.scale;
let top = this.scene.decisions[index].y dy / this.scene.scale;
this.$set(this.scene.decisions, index, Object.assign(this.scene.decisions[index], {
x: left,
y: top,
}));
},
Комментарии:
1. Определите
not working
. Что это за сообщение об ошибке?2. Сообщение об ошибке: не удается прочитать свойство ‘x’ из undefined
3. Где, как будто я комментирую один из этих двух методов, другой метод работает нормально
4. Вы должны проверить,
let index
присваивается ли нулевое значение — и немедленно выйти из функции в таком случае.5. позвольте мне попробовать это