0👍
You can use destructuration in ES6 to get targeted element, in your case :
<button :href="'{% url 'follow' recipe.added_by.id %}'" @click="followUser">Obserwuj</button>
////
methods: {
followUser({ target }) {
const url = target.getAttribute('href')
axios.post(url)
.then(response => {
console.log(response.data);
})
.catch(errors => {
if (errors.response.status == 401){
window.location = '/login';
}
});
}
},
- [Vuejs]-Multiple fields search form without duplicating the component for each search condition
- [Vuejs]-Vue reactivity issues in component making asynchronous server requests
0👍
You cannot send a POST request via URL because the post parameters are not sent via the URL but you can use an alternate solution and instead of using a link to use a button that looks like a link and is in a form: How to make button look like a link? make-button-look-like-a-link.
have a good day, hope you find it helpful.
Source:stackexchange.com