Skip to content

Latest commit

 

History

History
66 lines (48 loc) · 1.77 KB

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

File metadata and controls

66 lines (48 loc) · 1.77 KB
pageClass sidebarDepth title description
rule-details
0
vue/no-this-in-before-route-enter
disallow `this` usage in a `beforeRouteEnter` method

vue/no-this-in-before-route-enter

disallow this usage in a beforeRouteEnter method

  • This rule has not been released yet.

📖 Rule Details

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

<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>

🔧 Options

Nothing.

🔇 When Not To Use It

When vue-router is not installed.

📚 Further Reading

vue-router - in-component-guards

🔍 Implementation