Cannot access to this.$router in custom method
See original GitHub issueHi, i would like to access to this.$router.push('/home')
in a custom method, i get this error Cannot read property 'push' of undefined
import Vue from 'vue'
import Component from 'vue-class-component'
import AuthService from "../../../../main/services/api/auth/auth.service";
@Component
export default class Login extends Vue {
login: string = "";
password: string = "";
/**
* Classes
*/
authService = this.$container.get<AuthService>(AuthService.name);
submit() {
console.log('login: ' + this.login);
console.log('password: ' + this.password);
this.authService.login(this.login, this.password).then((res) => {
console.log(this);
this.$router.push('/home');
});
return false;
}
mounted() {
console.log(this);
}
}
<template>
<div>
<form v-on:submit.prevent="submit()">
<input name="login" v-model="login"/><br>
<input name="password" type="password" v-model="password"/>
<button type="submit"></button>
</form>
</div>
</template>
<script lang="ts">
import Login from './Login'
export default Login
</script>
<style scoped>
</style>
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:11 (4 by maintainers)
Top Results From Across the Web
vue-router can't access my component - Stack Overflow
The thing I need to say is, that I am adding a new route after a userinput and then I can't access to...
Read more >How To Navigate Between Views with Vue Router
In your text editor, open the AirportDetail.vue component. To achieve this, detect if airport.value is undefined. This function will be called ...
Read more >Complete Vue Router 4 Guide: Basics, Programmatic Routing ...
The createRouter method is what we use to create a new Vue Router instance. ... We cannot just directly open our file in...
Read more >Angular Router: Child Routes, Auxiliary Routes, Master Detail
Learn how to use the Angular Router, avoid common pitfalls, learn Child Routes, Auxiliary Routes, setup a Master Detail Routing Scenario.
Read more >Testing Vue Router
The best way to illustrate how to test an app using Vue Router is to let the warnings guide us. The following minimal...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @Worie, i never found a solution unfortunately…
Closing as reproduction is not provided in a long time. Please open a new issue with a self-contained reproduction when you can follow up information.