Javascript Vue.js计算属性中的奇怪行为

Javascript Vue.js计算属性中的奇怪行为,javascript,vue.js,object,Javascript,Vue.js,Object,我有一个computed()属性,其中包含以下console.log: props: { productGroup: { type: Object, default: {}, }, filterState: { type: Object, default: {}, } }, computed: { filterProducts() { console.log(this.productGroup.Polarized); // outputs --&

我有一个
computed()
属性,其中包含以下console.log:

props: {
 productGroup: {
   type: Object,
   default: {},
 },
 filterState: {
   type: Object,
   default: {},
 }
},

computed: {
filterProducts() {
  console.log(this.productGroup.Polarized);
      // outputs --> "{standard: {mirrored:TRUE: Array(8), mirrored:FALSE: Array(5)}}"

  console.log(this.filterState.size);
      // outputs --> "standard"

  console.log(this.productGroup.Polarized, this.productGroup.Polarized[this.filterState.size], this.filterState.size);
      // outputs "{standard: {mirrored:TRUE: Array(8), mirrored:FALSE: Array(5)}}",
                 "undefined", <------ why is that??
                 "standard"

  if (!this.productGroup.Polarized[this.filterState.size] &&
      !this.productGroup['Non-Polarized'][this.filterState.size] &&
      !this.productGroup['Elite Polarized'][this.filterState.size]) {
    return false;
  }
  ...
  ...
  return ...
}
道具:{
产品组:{
类型:对象,
默认值:{},
},
过滤器状态:{
类型:对象,
默认值:{},
}
},
计算:{
filterProducts(){
console.log(this.productGroup.log);
//输出-->“{standard:{mirrored:TRUE:Array(8),mirrored:FALSE:Array(5)}”
console.log(this.filterstState.size);
//输出-->“标准”
log(this.productGroup.Polarized,this.productGroup.Polarized[this.filterState.size],this.filterState.size);
//输出“{standard:{mirrored:TRUE:Array(8),mirrored:FALSE:Array(5)}”,
“未定义”{
log(this.productGroup.Polarized,this.productGroup.Polarized[this.filterState.size],this.filterState.size);
}, 1000)
//输出-->“{standard:{mirrored:TRUE:Array(8),mirrored:FALSE:Array(5)}”,

//{镜像:真:数组(8),镜像:假:数组(5)},是否在组件上动态设置了道具?您可能会遇到竞争条件,在使用继承的道具更新之前,组件道具仍在使用默认值:因此setTimeout有效。看起来像
this.productGroup.Polarized
是一个字符串,因为
“{standard:{mirrored:TRUE:Array(8),mirrored:FALSE:Array(5)}“
看起来一点也不像一个有效的对象-而且因为字符串没有这样的属性,所以它有“standard”,结果是
undefined
@JaromandaX-Nah,我认为OP添加引号只是为了在控制台中显示他看到的输出。控制台是一个糟糕的调试工具,因为它具有实时对象更新功能。如果必须使用它,请尝试
console.log(JSON.stringify(whateverObjectYouWantToDebug))
但我强烈建议使用实际的调试程序这可能是的副本,但会等待,看看组件上是否动态设置了道具?在使用继承的道具更新之前,您可能会遇到竞争条件,组件道具仍使用默认值:因此setTimeout有效。看起来de>this.productGroup.Polarized
是一个字符串,因为
的{standard:{mirrored:TRUE:Array(8),mirrored:FALSE:Array(5)}}}“
看起来与有效对象完全不同,而且由于字符串没有这样的属性,所以它具有“standard”,结果是
undefined
@JaromandaX-Nah,我认为OP添加引号只是为了在控制台中显示他看到的输出。控制台是一个糟糕的调试工具,因为它具有实时对象更新功能。如果必须使用它,请尝试
console.log(JSON.stringify(whateverObjectYouWantToDebug))
但我强烈建议使用实际的调试程序这可能是的副本,但将拭目以待
setTimeout(() => {
console.log(this.productGroup.Polarized, this.productGroup.Polarized[this.filterState.size], this.filterState.size);
}, 1000)

//outputs --> "{standard: {mirrored:TRUE: Array(8), mirrored:FALSE: Array(5)}}",
//            "{mirrored:TRUE: Array(8), mirrored:FALSE: Array(5)}", <---- correct output
//            "standard"