【发布时间】:2019-08-03 13:47:52
【问题描述】:
我正在尝试使用以下方法更新我的 VueJS 页面。为了演示它在哪里工作以及在哪里不工作,我在下面添加了解释,但我被困住了如何绑定数据。
<script>
window.app = new Vue({
el: '#app',
data: {
form: {
email: '',
password: ''
},
token: ''
},
methods: {
onSubmit(e) {
e.preventDefault();
this.token = "This works!"
// alert(JSON.stringify(this.form))
axios.post('http://localhost:5000/login', {
username: this.form.email,
password: this.form.password
})
.then(function (response) {
// this.token = response.data.access_token
this.token = "This does not work!"
console.log(response);
})
.catch(function (error) {
console.log(error);
});
},
onReset(e) {
e.preventDefault()
// Reset our form values
this.form.email = ''
this.form.password = ''
}
}
})
</script>
【问题讨论】:
-
你的数据对象在哪里?
-
刚刚更新了完整的脚本标签