Skip to content

Files

Latest commit

 

History

History
46 lines (34 loc) · 1.01 KB

no-this-in-before-route-enter.md

File metadata and controls

46 lines (34 loc) · 1.01 KB

Pattern: Use of this in beforeRouteEnter

Issue: -

Description

Because lack of this in the beforeRouteEnter (docs). This behavior isn't obvious, so it's pretty easy to make a TypeError.

<script>
export default {
  beforeRouteEnter() {
    /* ✗ BAD */
    this.method(); // Uncaught TypeError: Cannot read property 'method' of undefined
    this.attribute = 42;
    if (this.value === 42) {
    }
    this.attribute = this.method();
  }   
}
</script>
<script>
export default {
  beforeRouteEnter() {
    /* ✓ GOOD */
    // anything without this
  }   
}
</script>

Further Reading