1

I'm just starting a Vue TypeScript project 3 hour ago,

Just finishing setting rules eslint and tslint and make the "formatter" does the "rules" want and I'm happy about it,

And now I just want to know how to use created / mounted that will call function when the app / page refresh, because I read the documenttation and try it with no luck.

<template>
  <v-app>
    <v-main>
      <p>{{ name }}</p>
    </v-main>
  </v-app>
</template>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';

@Component({
  components: {},
})
export default class App extends Vue {
  name: string = 'hello';
  constructor() {
    super();
    this.test();
  }
  onClick() {
    console.log('clicked');
    this.name = 'Clicked Hello';
  }

  test = (): void => {
    this.name = 'Hello Wrold!';
    console.log('this is test and called');
  };

  mounted = (): void => {
    this.test();
  };

  created = (): void => {
    this.test();
  };
}
</script>

I just want to call a function from the start, I know this is very basic, but yeah it's not working for me and I need help for it.

the code from tutorial and answer is work, I just need to re-open the project and start again. But also I use the different answer because less warning for me.

1 Answer 1

3

Here, you declared data properties that are functions, not methods or hooks. These should not be anonymous functions because they actually need a binded this.

@Component
export default class App extends Vue {
   test (): void {
      console.log('Hello')
   }

   created () {
     this.test()
   }

   mounted () {
     this.test()
   }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.