Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vue3 class component access props

i use vue3 with class-component in typescript my class looks like:

import {Options, Vue} from "vue-class-component";

@Options({
  props: {
    result: Object
  }
})


export default class imageResult extends Vue {
  currentImage = 0;

  getSlides(){
    console.log('result',this.$props.result); // not working
    console.log('result',this.result); // not working too
  }

My question is, how can i access and use the property within my class?

both this.result and this.$props.result throws me an error.

can someone help me? Thanks in advance

like image 413
Hansinger Avatar asked Apr 14 '26 16:04

Hansinger


1 Answers

late answer but maybe it helps someone in the future. works for me with vu3 & typescript

<script lang="ts"> 
import { Vue, prop } from "vue-class-component";

export class Props {
  result = prop<string>({ required: true });
}

export default class Foo extends Vue.with(Props) {
  test(): void {
    console.log(this.result);
  }
}
</script>
like image 52
constantin Avatar answered Apr 17 '26 18:04

constantin