我有一个帮助过滤数据的函数.当用户更改 Select 时,我使用v-on:change
,但我还需要在用户 Select 数据之前调用该函数.我之前使用ng-init
对AngularJS
也做了同样的操作,但我知道vue.js
中没有这样的指令
这是我的职责:
getUnits: function () {
var input = {block: this.block, floor: this.floor, unit_type: this.unit_type, status: this.status};
this.$http.post('/admin/units', input).then(function (response) {
console.log(response.data);
this.units = response.data;
}, function (response) {
console.log(response)
});
}
在blade
文件中,我使用blade forms执行过滤器:
<div class="large-2 columns">
{!! Form::select('floor', $floors,null, ['class'=>'form-control', 'placeholder'=>'All Floors', 'v-model'=>'floor', 'v-on:change'=>'getUnits()' ]) !!}
</div>
<div class="large-3 columns">
{!! Form::select('unit_type', $unit_types,null, ['class'=>'form-control', 'placeholder'=>'All Unit Types', 'v-model'=>'unit_type', 'v-on:change'=>'getUnits()' ]) !!}
</div>
当我 Select 一个特定的项目时,这很好用.然后,如果我点击所有,比如说all floors
,它就工作了.我需要的是,当页面加载时,它调用getUnits
方法,该方法将使用空输入执行$http.post
.在后端,我处理请求的方式是,如果输入为空,它将提供所有数据.
我怎么能在vuejs2
分钟内做到这一点?