【发布时间】:2021-03-16 16:26:53
【问题描述】:
我的数据中有一个空的object,例如:
data: () => {
return {
lines: []
}
}
我想从我在“mounted”中定义的函数中推入一些数组,构造函数如下:
function setLine() {
class Line {
constructor(x1, y1, x2, y2, stroke) {
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
this.stroke = stroke;
}
}
let x1 = localStorage.getItem("x1")
let y1 = localStorage.getItem("y1")
let x2 = localStorage.getItem("x2")
let y2 = localStorage.getItem("y2")
let stroke = localStorage.getItem("stroke")
console.log(x1, y1, x2, y2, stroke)
let lines = [
new Line(x1, y1, x2, y2, stroke)
]
localStorage.setItem("lines", JSON.stringify(lines))
}
在我的存储中添加一行非常有效,但即使我尝试写:
this.objects = lines,它不会更新我在数据中的对象...
谁能告诉我该怎么做?
【问题讨论】:
标签: javascript vuejs2 vue-component