【发布时间】:2020-10-21 22:56:03
【问题描述】:
我尝试使用 vue 和 axios 从 :href 元素发送帖子,但我不知道如何从 :href 填充 axios url 参数。
我试试这个:
<div id="follow">
<a :href="'{% url 'follow' recipe.added_by.id %}'" @click="followUser()">Obserwuj</a>
</div>
Href 元素填充了 Django 模板标签,并且工作正常。
我的vue和axios代码:
methods: {
followUser() {
axios.post()
.then(response => {
console.log(response.data);
})
.catch(errors => {
if (errors.response.status == 401){
window.location = '/login';
}
});
}
},
当我点击链接时,出现错误:“TypeError:errors.response is undefined”
【问题讨论】:
-
渲染出来的 HTML 是什么样子的?我希望
document.querySelector("#follow a").getAttribute("href")在任何框架中
标签: javascript vue.js axios