Utilize Firestore's limit feature with variables

Is it possible to utilize a variable (page) in the limit parameter within Firebase Firestore while using Vue?


export default {
  data() {
    return {
      page: 1,
    }
  },
  methods: {
  },
  firestore: {
    Words: db.collection("Words").where("incomplete", "==", true).limit(this.page)
  },
}

Unfortunately, this approach is not successful as it results in the following error:

Cannot read property 'page' of undefined

I've attempted using firebase.page and simply page, but I'm unable to figure out how to properly incorporate the variable in this manner. Any suggestions on how to achieve this?

Answer №1

The issue at hand pertains to the interpretation of "this" outside of a function context. Although I am not utilizing vuefire myself, after examining the documentation, it seems that the firestore property can also be declared as a function, similar to data(). This approach provides a functional environment for the usage of this...

data() {
  return {
    Words: [],
    page: 1,
  }
},
methods: {
},
firestore() {
  return {
    Words: db.collection("Words").where("incomplete", "==", true).limit(this.page),
  }
},

It's worth noting (another insight from browsing vuefire docs) that in order for Words to be properly linked to the instance, the property must be present in both the data() and firestore() functions.

Answer №2

The issue you are experiencing is not related to Firestore but instead is due to the limited accessibility of this within your custom $option firestore.

To resolve this, consider implementing the following solution:

methods: {
  firestore() {
    return db.collection("Words").where("incomplete", "==", true).limit(this.page).get()
  }
},

It's important to note that this function will return a Promise that needs to be handled appropriately.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The error message for validating my form magically disappears

I've been working on creating a registration form using HTML, Bootstrap, and JavaScript. My goal was to display an error message when a field is left empty, but for some reason, the error message appears briefly and disappears afterwards. I can't ...

The function Document.getElementsByName() behaves differently in Internet Explorer, returning an object, compared to Chrome where it returns

While trying to meet my requirements, I encountered a discrepancy between running the page in IE browser versus Chrome. The code worked successfully in IE, but not in Chrome. for(var gridNo=0;gridNo < 30;gridNo++){ var fldId = arry[0]+'_& ...

Getting a vector layer from JSON in OpenLayers 3 can be achieved by following these steps

Below is the script where I have included vector layers vectorLayer, vectorLayer5, vectorLayer1 How can I retrieve that layer from JSON.. I want to add multiple layers from an external JSON file with the icon PNG image // Updated on input change var ra ...

Enable lodash access throughout a React Native application

Is it possible to have lodash automatically accessible in all files within a React Native project without needing to import it every time? ...

Unable to open modal in browser due to HTML, CSS, and jQuery issues

I'm having trouble creating a modal window that opens when a button is clicked for user registration. The button is being clicked, but the modal window isn't appearing. Here's my code: <script src="http://ajax.googleapis.com/ajax/libs/ ...

TranslateY animation glitching

I need help with expanding a box to 100% height after click, then collapsing and sticking to the bottom. I created a function in Vue framework to handle the animation, but it's not working smoothly. How can I make it less buggy? Check out the demo her ...

What could be causing this Vue.js component to show the body of a function instead of its intended output?

I'm currently developing a small Todo App using Vue 3 for the front-end and Slim 3 for the back-end (API). Within App.vue, you'll find: <template> <div id="app"> <Header title="My todo list" :un ...

What is the best way to change the name of a property within an object

I need to update the names of properties in a nested object. { 0: {value: "can_view"}, 1: {value: "can_create"} } The desired output should be: { user_can: "can_view", user_view: "can_create" } ...

What is the best way to apply typography theme defaults to standard tags using Material-UI?

After reading the documentation on https://material-ui.com/style/typography/ and loading the Roboto font, I expected a simple component like this: const theme = createMuiTheme(); const App = () => { return ( <MuiThemeProvider theme={theme}> ...

The ins and outs of function returns and callback mechanisms

I'm encountering an issue related to the order of my functions and I can't figure out the reason behind it. When I hover over the call for function_2 inside the first function, VSCode shows me the result as Promise<void>, and the console p ...

How can I ensure the button remains disabled until all inputs are completed in Redux form?

I am currently studying a react-redux form example that you can find at the following link: In this example, the submit button is enabled if the user fills in at least one input field. I am curious to know if there is a way to enable the button only when ...

Angular: displaying dates in a specific format while disregarding time zones

Is there a way to format date-time in Angular using DatePipe.format() without converting timezones, regardless of location? For instance, for various examples worldwide (ignoring time differences) I would like to obtain 07/06/2022: console.log('2022-0 ...

A streamlined method for generating an array containing all numerical string values

I'm looking to generate an array of digits in JavaScript. Currently, I have hard-coded it like this: const digitGeneration = ['0', '1', '2', '3', '4', '5', '6', '7', &apo ...

Fetching values from dynamically generated elements in a Vue.js loop

I am currently working on creating a table that includes checkboxes and text fields based on an array of items, essentially building a "questionnaire" where the questions are pulled from a database. My question now is how can I efficiently retrieve inform ...

Interact with the exe/jar files on a remote machine using JavaScript

I've been tasked with finding a way to access an executable file (or any file located in a specific location like the C drive) directly from a web browser. The idea is to have a button on a webpage that, when clicked, will run the executable and pass ...

Guide to adding information to a file in Nodejs depending on a condition

Looking for assistance on how to append an annotation (@Circuit(name = backendB)) to a file if the "createEvent" name exists and the annotation is not already present. I am unsure of the process, so any help on checking and appending using streams would ...

Enhance the functionality of your Rails application by implementing Ajax or jQuery to asynchronously load table elements separately from the page

Currently, I am facing an issue with a page that displays a list of user sites. The problem lies in the fact that I am making an API call for each site to check its status, which is causing the page to load very slowly. To address this issue, I would like ...

You will encounter a TypeError with the message "Super expression must be null or a function" when attempting to export a named class

I'm experimenting with components. I have a default export in place but now I think I need to create a named class for my next export. Take a look at the code below: export default Users; import React from 'react'; export class UsersTest e ...

What could be the reason for my electron application consistently displaying false results when using Google Authenticator, despite entering the correct token?

Within this snippet of code, I am initiating a request to the main process to create a QR code using speakeasy and qrcode. document.addEventListener('DOMContentLoaded', async function() { const data = await ipcRenderer.invoke('generate-q ...

Measuring Load Time Percentage in AngularJS Using $http Requests

I am currently utilizing Angular with my Rails application. I have a sample app and I am interested in displaying the response time required to load a response in Angular. For example, When loading a response of an array containing 100,000 elements, I w ...