是否可以将外键值分配给vue.js中数据对象中的变量?
我想要做的就是获取当前的user_id和work_id来保存到数据库中。 user_id和work_id是来自其他表的外键。
<script>
export default {
data() {
return{
editmode: false,
works:{},
index:1,
form: new Form({
work_name:'',
description:'',
payment:'',
location:'',
end_date:'',
}),
work_id:'1', //how to get work_id that i choose?
user_id:'1', //how to get the current user id?
}
},
methods:{
editModel(work){
this.editmode = false;
this.form.reset();
$('#addNewModal').modal('show')
this.form.fill(work);
},
loadWork(){
if(this.$gate.isChairman()){
axios.get('api/work').then(({data})=>(this.works = data));
}
},
createApplication(){
this.$Progress.start();
axios.post('api/application',{application:'apply', user_id:this.user_id, work_id:this.work_id}).then(()=>{Fire.$emit('AfterEvent');
$('#addNewModal').modal('hide')
Toast.fire({
type: 'success',
title: 'Work Application success'
})
this.$Progress.finish();
})
.catch(()=>{
this.$Progress.fail();
})
}
},
created() {
this.loadWork();
Fire.$on('AfterEvent',() => {this.loadWork()});
}
}
</script>