0
What if you remove the catch part of your axios function
return axios.post(`${serv}/${ressource}`,
{
data: params,
},
{headers: {'Authorization': 'Bearer ' + token}})
.then((response) => response = response.data)
and catch it where you want to show the toast. Login.vue:
function logUser () {
return postRequest()
.then(responseData => {
//do your stuff
})
.catch((err) => {
this.$toast.error(err.response.data.message)
throw err.response.data.message
})
}
Update:
The solutions is actual pretty easy. You just need add your method where this
needs to be the vue instance to your component.
See following example:
accessVueInstance.js:
export function compare(vueInstance) {
return this === vueInstance
}
MyComponent.vue:
import the function
import { compare } from "./accessVueInstance"
add the function to your component:
if you use class components:
export default class MyComponent extends Vue {
compare = compare
created() {
console.log(this.compare(this)) //will log true
}
//your stuff
}
else:
methods: {
compare
},
created() {
console.log(this.compare(this)) //will log true
}
Vue automatically binds the this value for methods so that it always
refers to the component instance.
See it in action codesandbox.io
- [Vuejs]-PrimeVue – is there any way to hide the row selection column in the DataTable component?
- [Vuejs]-Use v-for in Templates (Vue-Tables-2)
Source:stackexchange.com