vue-class-component icon indicating copy to clipboard operation
vue-class-component copied to clipboard

init data by access props is undefinded

Open kagaricyan opened this issue 2 years ago • 7 comments

code example:

<template>
  <span>{{ test }}-{{ local }}</span>
</template>

<script>
import { Component, Prop, Vue } from 'vue-property-decorator';

@Component
export default class HelloWorld extends Vue {
  @Prop({default: ()=>({aaa: 456})}) msg;

  local = JSON.parse(JSON.stringify(this.msg));

  get test() {
    return this.msg.aaa;
  }
}
</script>

this code is works in lower version. recent days,i want to upgrade my dependencies, but get problems with this code.

kagaricyan avatar Jun 24 '22 06:06 kagaricyan

I've also run into this issue when updating to the latest versions. It seems to be related with dev-deps, because when we left that untouched, it works just fine. We're still trying to figure this one out and see which dep causes this behavior.

CptMeatball avatar Jul 04 '22 11:07 CptMeatball

Just had this issue. Downgrading to TypeScript 4.2.4 fixed it.

twrayden avatar Jul 13 '22 04:07 twrayden

Does anyone has a workaround for this that does not involve downgrading Typescript? We can't downgrade our typescript version and we haven't found a way to solve this issue.

pieterzeilstra avatar Jul 22 '22 13:07 pieterzeilstra

I decide rewrite all class component using composition api

kagaricyan avatar Jul 22 '22 13:07 kagaricyan

Added in tsconfig.json, now its working fine for me "useDefineForClassFields": false,

tested on typescript v. 4.7.4

farazshuja avatar Aug 02 '22 07:08 farazshuja

Added in tsconfig.json, now its working fine for me "useDefineForClassFields": false,

tested on typescript v. 4.7.4

@farazshuja really appreciate your comment help me fixing my legacy project! For someone else meet this problem, here is the typescript 4.3 breaking change.

bchen1029 avatar Nov 14 '22 02:11 bchen1029

I'm not sure but it seems that putting the props definition after the data definition also work for me. Can anyone confirm or explain why ? Sorry I'm not typescript fluent.

<template>
  <span>{{ test }}-{{ local }}</span>
</template>

<script>
import { Component, Prop, Vue } from 'vue-property-decorator';

@Component
export default class HelloWorld extends Vue {

  /* data first */
  local = JSON.parse(JSON.stringify(this.msg));

  @Prop({default: ()=>({aaa: 456})}) msg;

  get test() {
    return this.msg.aaa;
  }
}
</script>

SarguelUnda avatar Dec 01 '22 15:12 SarguelUnda