pageClass | sidebarDepth | title | description | since |
---|---|---|---|---|
rule-details |
0 |
vue/no-this-in-before-route-enter |
disallow `this` usage in a `beforeRouteEnter` method |
v7.11.0 |
disallow
this
usage in abeforeRouteEnter
method
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>
Nothing.
When vue-router is not installed.
vue-router - in-component-guards
This rule was introduced in eslint-plugin-vue v7.11.0