2
Laravelでvuejsを開始したばかりなので、axios
httpクライアントライブラリで投稿をリクエストしようとしています。 要求はうまく動作しますが、エラーメッセージをhtmlファイルに表示できません。ここでVuejs:ajax検証エラーメッセージが表示されない
は、htmlファイルが
<form @submit.prevent="addJob" >
<input type="text" v-model="user.name" >
<textarea v-model="user.message"></textarea>
<button >Submit</button>
//for showing errors
<span v-if="error">{{error}} </span>
</form>
あるJsの
export default {
data:function(){
return {
test:'hello',
more:[
{ message: 'Foo' },
{ message: 'Bar' }
],
origin:'',
user:{},
error:''
}
},
methods:{
addJob:function(e){
axios.post('/test',this.user)
.then(function (response) {
//set the error message
this.$set('error',response.data.errors);
//this will returns nothing
console.log(error);
})
.catch(function (error) {
});
}
}
}
response.data.errors
はエラーメッセージを返しますが、私は、HTMLページに表示することができませんが。この
そのは – Jabaa
を働いていない私はthis.error = response.data.errors – Jabaa
に変更したときにwokedもう1つの質問ajaxリクエストの後に成功/エラーメッセージテンプレートを表示する方法 – Jabaa