我有一个有助于过滤数据的功能.我在v-on:change
用户更改选择时使用,但我甚至需要在用户选择数据之前调用该函数.我AngularJS
以前使用过的方法也一样,ng-init
但据我所知,没有这样的指令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)
});
}
Run Code Online (Sandbox Code Playgroud)
在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>
Run Code Online (Sandbox Code Playgroud)
当我选择特定项目时,此工作正常.然后,如果我点击所有让我们说all floors
,它的工作原理.我需要的是当页面加载时,它调用getUnits
将执行$http.post
空输入的方法.在后端,我已经处理了请求,如果输入为空,它将提供所有数据.
我怎么能这样做 …
如何在数据中使用计算属性或通过总线发送?
我有以下vue实例,但myComputed总是未定义但是computedData正常工作.
var vm = new Vue({
data(){
return{
myComputed: this.computedData
}
},
computed: {
computedData(){
return 'Hello World'
}
}
})
Run Code Online (Sandbox Code Playgroud) 是否有一个布尔值我们可以在每个组件实例中访问以了解组件何时安装?
就像是:
<template>
<div>
<span v-if="$mounted">I am mounted</span>
<span v-if="$created">I am created</span>
<span>Called before created and mounted</span>
</div>
</template>
Run Code Online (Sandbox Code Playgroud)