【问题标题】:How to watch object in vue js?如何在 vue js 中查看对象?
【发布时间】:2021-11-17 09:10:46
【问题描述】:

我有经度和纬度的对象?

data(){
  return{
  center2:{lat:0,lng:0}
}

}

我正在尝试这样观看,但无法正常工作

 watch:{
    "center2.lat":function (newValue, oldValue) {
     
      this.center2.lat = newValue;
    }
    , "center2.lng":function (newValue, oldValue) {
     
      this.center2.lng = newValue;
    }
    },

我该怎么做?

【问题讨论】:

标签: javascript vue.js vuejs3


【解决方案1】:

请考虑这个代码示例。

  1. Vue 监视子属性

    观看:{ 'item.someOtherProp'(newVal){ //处理“myArray”中的更改 }, 'item.prop'(newVal){ //处理道具的变化 } }

  2. Vue 监视对象成员

    观看:{ 物品: { 处理程序(val){ // 做东西 }, 深:真 } }

另外请考虑这个参考。https://vuejs.org/v2/api/#watch。您可以深入观察对象的变化。

【讨论】:

猜你喜欢
  • 2022-01-24
  • 2018-12-01
  • 1970-01-01
  • 2019-10-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-21
相关资源
最近更新 更多