相关疑难解决方法(0)

如何在页面加载时调用vue.js函数

我有一个有助于过滤数据的功能.我在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空输入的方法.在后端,我已经处理了请求,如果输入为空,它将提供所有数据.

我怎么能这样做 …

javascript vue.js vuejs2

74
推荐指数
4
解决办法
13万
查看次数

在Vuejs中的数据中使用计算属性

如何在数据中使用计算属性或通过总线发送?

我有以下vue实例,但myComputed总是未定义但是computedData正常工作.

var vm = new Vue({
  data(){
    return{
      myComputed: this.computedData
    }
  },

  computed: {
    computedData(){
      return 'Hello World'
    }
  }
})
Run Code Online (Sandbox Code Playgroud)

vue.js vue-component vuejs2

13
推荐指数
2
解决办法
7248
查看次数

Vue.js:有没有办法知道组件实例何时被挂载?

是否有一个布尔值我们可以在每个组件实例中访问以了解组件何时安装?

就像是:

<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)

vue.js vuejs2

6
推荐指数
1
解决办法
6537
查看次数

标签 统计

vue.js ×3

vuejs2 ×3

javascript ×1

vue-component ×1