【发布时间】:2020-07-13 22:39:53
【问题描述】:
我有一个带有此代码的刀片。
<meta name="csrf-token" content="{{ csrf_token() }}">
<covid-form>
</covid-form>
然后在我的 covid-form 组件中,我得到了一个这样的表单:
<form @submit.prevent="send">
<input type="hidden" name="_token" :value="csrf">
我的组件脚本。
<script>
export default {
data(){
return{
csrf: document.head.querySelector('meta[name="csrf-token"]').content,
fullname:'',
phone:'',
nationality:'',
have_not_travelled_to_china:false,
have_not_travelled_to_others:false,
have_not_travelled_to_asian:false,
no_issue_to_stay_home:false,
no_symptomps:false,
dont_have_close_contact:false,
signDate:new Date(),
opts:{
format: 'YYYY-MM-DD',
showClear: true,
showClose: true,
useCurrent: false,
},
date: new Date(),
opt:{
format: 'YYYY-MM-DD HH:mm A',
showClear: true,
showClose: true,
useCurrent: false,
}
}
},
created(){
console.log(this.csrf)
},
methods:{
async send(){
let loader = this.$loading.show({
container: this.fullPage ? null : this.$refs.formContainer,
onCancel: this.onCancel,
color: '#c91010',
loader: 'bars',
width: 80,
height: 100,
})
await axios.post('/submitForm',{
agent_name: this.fullname,
phone: this.phone,
nationality: this.nationality,
have_not_travelled_to_china: this.have_not_travelled_to_china,
have_not_travelled_to_others: this.have_not_travelled_to_others,
have_not_travelled_to_asian: this.have_not_travelled_to_asian,
no_issue_to_stay_home: this.no_issue_to_stay_home,
no_symptomps: this.no_symptomps,
dont_have_close_contact: this.dont_have_close_contact,
signDate: this.signDate,
date: this.date
})
.then(()=>{
swal.fire({
title: 'Success!',
icon: 'success',
width: '500px'
});
loader.hide()
})
}
}
}
</script>
更新:
我在控制台中没有任何错误。在邮递员中使用127.0.0.1:8000/submitForm 进行了尝试,并提出了发布请求。但是每次我提交我都会得到"message": "CSRF token mismatch.",。我还删除了刀片中的@csrf,因为它已经在标题中
【问题讨论】:
标签: javascript php laravel vue.js csrf