Vuejs2 Vue计算属性未更新对象文字

Vuejs2 Vue计算属性未更新对象文字,vuejs2,computed-properties,Vuejs2,Computed Properties,我正在构建一个GeoJSON编辑器,它在中显示预览。挑战之一是将GeoJSON的坐标转换为横向,作为、或中的道具。我的解决方案是使用计算属性。因此,当GeoJSON更改时,映射对象也会更改。像这样: computed: { mapObject() { // If the geometry is a point, just assign geometry.coordinates into `lat` and `lng` if (this.$data.geo

我正在构建一个GeoJSON编辑器,它在中显示预览。挑战之一是将GeoJSON的
坐标
转换为
横向
,作为
中的道具。我的解决方案是使用计算属性。因此,当GeoJSON更改时,映射对象也会更改。像这样:

computed: {
    mapObject() {

        // If the geometry is a point, just assign geometry.coordinates into `lat` and `lng`
        if (this.$data.geometry.type === "Point") return ({
            lat: this.$data.geometry.coordinates[1],
            lng: this.$data.geometry.coordinates[0],
        });

        // If it's a polygon, grab the first set of coordinates (we aren't supporting polygons with holes for now).
        // then splice off the last element (Google Maps' polygon automatically loop the shape, unlike GeoJSON's convention),
        // then we map the values into an array of LatLngLiterals.
        if (this.$data.geometry.type === "Polygon") return this.$data.geometry.coordinates[0].splice(-1, 1).map(e => ({lat: e[1], lng: e[0]}));

        // If it's a LineString, do as above, without the splicing.
        if (this.$data.geometry.type === "LineString") return this.$data.geometry.coordinates.map(e => ({lat: e[1], lng: e[0]}));
    }
},

问题是,对于
类型,这不会更新。不过,对于
Polygon
LineString
类型来说,这似乎效果不错。如果有任何帮助,我们将不胜感激。

您如何更新该点?@skille
此。$data.geometry
v-model
的一个子组件,一个自定义输入。您是否尝试过将一些控制台登录到
mapObject
?它可能有助于确定than函数在您希望它运行时是否正在运行,或者它是否以某种方式返回了错误的值。@如果
块执行得很好,
几何体。键入
读取
,则该值不会更新。如果计算出的函数正在运行,则该值将被更新。这就引出了一个问题,您如何确定该值没有更新?似乎是其他东西没有更新,而不是
mapObject
本身。要尝试的其他操作:在computed函数中添加
console.log(this)
,然后在控制台中的
mapObject
属性更新后展开该属性的值。