【发布时间】:2017-04-04 12:03:55
【问题描述】:
我有一个帮助过滤数据的功能。当用户更改选择时,我正在使用v-on:change,但我还需要在用户选择数据之前调用该函数。我之前使用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 文件中,我使用刀片表单来执行过滤器:
<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>
当我选择特定项目时,这很好用。然后,如果我点击所有让我们说all floors,它就可以工作。我需要的是当页面加载时,它调用getUnits 方法,该方法将使用空输入执行$http.post。在后端,我以某种方式处理请求,如果输入为空,它将提供所有数据。
如何在vuejs2 中执行此操作?
【问题讨论】:
标签: javascript vue.js vuejs2