JS.VUE.NO.THIS.IN.BEFORE.ROUTE.ENTER

Should be no `this` in the `beforeRouteEnter`

Rule Details

Because lack of this in the beforeRouteEnter (docs) (https://router.vuejs.org/guide/advanced/navigation-guards.html#in-component-guards). This behavior isn't obvious, so it's pretty easy to make a TypeError. Especially during some refactor.

{'vue/no-this-in-before-route-enter': ['error']}

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

{'vue/no-this-in-before-route-enter': ['error']}

Copy
<script>
export default {
  beforeRouteEnter() {
    /* GOOD */
    // anything without this
  }   
}
</script>

Options

Nothing.

When Not To Use It

When vue-router (https://router.vuejs.org/) is not installed.

Further Reading

vue-router - in-component-guards (https://router.vuejs.org/guide/advanced/navigation-guards.html#in-component-guards)

The content on this page is adapted from the ESLint User Guide. Copyright © OpenJS Foundation and other contributors, www.openjsf.org. All rights reserved. https://eslint.org/docs/rules/