0

I created a function that should set a var equal to a variable in data.

export default class App extends Vue{
  data() {
    return {
      evidence: 0
    }
  }
  handleFileSelect(evt: any) {
      var evidence = this.evidence;
  }
};

The problem is that it shows an error saying "Property 'evidence' does not exist on type 'App'".

3 Answers 3

2

In vuejs functions should be in the methods section where you can use the data within the vue instance. Read here in detail.

Hence your code should be as below.

export default class App extends Vue{
 data() {
    return {
      evidence: 0
    }
 },
 methods: {
  handleFileSelect(evt: any) {
      var evidence = this.evidence;
  }
 }
};
Sign up to request clarification or add additional context in comments.

Comments

1

I'm no TypeScript guru, but this should work..

export default class App extends Vue{
  data() {
    return {
      evidence: 0
    }
  },

  methods: {
     handleFileSelect(evt: any) {
        let evidence = this.evidence;
     }
  }
};

Comments

0

Using the decorator from vue-class-component:

import { Component, Vue } from "vue-property-decorator";

@Component
export default class App extends Vue {
  evidence = 0
}

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.