我在vue.js中有一个值数组,但问题是我需要将这些值传递给控制器。我怎么能这样做,或者这是错误的方式?
这是在我的vue.js中,我得到了值:
additional_features: this.additionals_features
this.$http.patch('/profile/'+ user_id +'/property/'+ property_id +'/edit', property_credentials).then(function(response) {
$("html, body").animate({ scrollTop: 0 }, "slow");
this.property_status = true;
this.property_success_update_message = response.data.successUpdateMsg;
} , function(response) {
$("html, body").animate({ scrollTop: 0 }, "slow");
this.property_status = false;
this.property_errors = response.data
});
这是我的控制器
$additional_features = $request->input('additionals_features');
这是我的HTML:
<input type="hidden" v-model="property_credentials.additional_features" name="additional_feature[]" value="@{{property_credentials.additional_features}}" />
答案 0 :(得分:4)
您可以使用vue-resource并使用帖子发送:
new Vue({
el: '#app',
data: {
token: '{{ csrf_token() }}',
property_credentials: {
additionals_features: [],
}
},
methods: {
submit: function() {
this.$http.post('/your-api-url', {
'_method': 'patch',
'_token': this.token, // You must pass this token on post requests
'additionals_features': this.property_credentials.additionals_features,
});
}
}
});
数据将直接到达您的控制器,因此您可能
$additional_features = $request->get('additionals_features');
一旦到达控制器,你对这些数据做了什么,这取决于你。