1、api.php
Route::post('/message/store','MessagesController@store');
2、controller
public function create(array $attributes){
return Message::create($attributes);
}
3、vue
<template>
<div>
<button class="btn btn-default pull-right msgbtn"
@click="showSendMessageFrom"
>发送私信
</button>
<div class="modal fade" id="modal-send-message" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button " class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">
发送私信
</h4>
</div>
<div class="modal-body">
<textarea v-modal="body" v-if="!status" name="body" class="form-control"></textarea>
<div class="alert alert-success" v-if="status">
<strong>私信发送成功</strong>
</div>
</div>
<!-- Modal Actions -->
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" @click="store">
发送私信
</button>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
props:['user'],
data(){
return {
body:'',
status:false
}
},
methods:{
store() {
this.$http.post('/api/message/store',{'user':this.user,'body':this.body}).then(response=>{
this.status = response.data.status;
setTimeout(function () {
$('#modal-send-message').modal('hide');
},2000);
});
},
showSendMessageFrom(){
$('#modal-send-message').modal('show');
}
}
}
</script>
4、注册vue
5、引入vue