vue/no-this-in-before-route-enter 정확성
작동 방식
beforeRouteEnter 메서드 내에서 this 사용을 금지합니다.
이 규칙은 vue-router를 사용할 때만 관련이 있습니다.
왜 문제가 되는가?
beforeRouteEnter 메서드 내부에서는 this에 접근할 수 없습니다. Vue Router 문서 참조. 이 동작은 명백하지 않으며, 따라서 이 린트 규칙은 일부 경우에 실행 시 오류를 방지하는 데 도움이 될 수 있습니다.
예시
이 규칙에 잘못된 코드 예시:
js
export default {
beforeRouteEnter(to, from, next) {
this.a; // 오류: 'this'는 사용할 수 없습니다
next();
},
};이 규칙에 올바른 코드 예시:
js
export default {
beforeRouteEnter(to, from, next) {
// 'this' 없이 수행할 수 있는 모든 작업
},
};사용 방법
구성 파일 또는 CLI를 통해 이 규칙을 활성화하려면 다음을 사용할 수 있습니다:
json
{
"plugins": ["vue"],
"rules": {
"vue/no-this-in-before-route-enter": "error"
}
}bash
oxlint --deny vue/no-this-in-before-route-enter --vue-plugin