Giter Site home page Giter Site logo

Comments (3)

posva avatar posva commented on May 19, 2024

You should probably watch inputText to unbind and bind as it changes.
For the firebase function, you can use a fallback content there: this.inputText || '' but this shouldn't be necessary since inputText should be defined. If you manage to provide a repro for that particular case, I'd look into it

from vuefire.

tgcsea avatar tgcsea commented on May 19, 2024

Thanks for the help! Here's how I changed the code in case someone finds it useful:

<template>
  <div>
    <form v-on:submit.prevent="onSubmit">
      <input type="text" v-model="inputText">
      <input type="submit" value="Search">
    </form>
    <p>{{ queryResult }}</p>
  </div>
</template>

<script>
import db from './firebasedb.js';
export default {
  name: 'test',
  data() {
    return {
      inputText: '',
      queryResult: {},
    }
  },
  methods: {
    onSubmit() {
      if (this.inputText) {
        this.$bindAsObject(
          'queryResult',
          db.ref('customers').orderByChild('firstName').equalTo(this.inputText)
        );
      }
    },
  },
}
</script>

This code is working as expected, but I have one more question: Do I need to add this.$unbind('queryResult'); before this.$bindAsObject(...) and add some logic for the case where onSubmit method is being called for the first time? Are there any drawbacks with this current solution?

from vuefire.

posva avatar posva commented on May 19, 2024

Yes, you need to (both questions).
You may be doing too many requests if no throttle is added (https://vuejs.org/v2/guide/migration.html#debounce-Param-Attribute-for-v-model-removed)

from vuefire.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.