Controlling data in Firebase collection using Vuex and Vuexfire

I have a question about using Vuexfire to import data from Firebase in Vuex.

const state = {
    ricettario: [] // contains all recipe objects
}
const actions = {
    init: firestoreAction(({ bindFirestoreRef }) => {
        bindFirestoreRef('ricettario', db.collection('ricettarioFirebase'))
    }),
}

While the current setup works perfectly for importing data, I am struggling with manipulating each document within the 'ricettarioFirebase' collection. In Vue.js and Firebase, this was easily done with .get() and .then().

I believe that utilizing GETTERS could be the solution, but as a newcomer to Vuex and Vuexfire, I am unsure of the correct approach.

In essence, I want to convert the traditional Firebase command shown below into Vuexfire:

db.collection("ricettarioFirebase")
      .orderBy("data")
      .get()
      .then(snapshot => {
        snapshot.forEach(doc => {
          let ricetta = doc.data();
          ricetta.data = dayjs(ricetta.data)
            .locale("it")
            .format("D MMMM YYYY");
          ricetta.diffClass = ricetta.diff.split(" ").join("_");
          this.ricettario.push(ricetta);
        });
      });

Within Vuexfire, my goal is to transform each object in 'ricettario[]' into "ricetta" and then modify the properties such as "ricetta.diffClass" and "ricetta.data".

Answer №1

When referencing the Vuexfire guide, it states:

Vuexfire does not manage writing data to Firebase, as you have direct access to the Firebase JS SDK for precise updates.

The documentation provides examples using the "standard" JS SDK, similar to traditional firebase commands mentioned in your inquiry. Therefore, incorporating database writes within Vuex can be achieved by utilizing Actions.

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

Searching for MongoDB / Mongoose - Using FindOneById with specific conditions to match the value of an array inside an object nestled within another array

Although the title of this question may be lengthy, I trust you grasp my meaning with an example. This represents my MongoDB structure: { "_id":{ "$oid":"62408e6bec1c0f7a413c093a" }, "visitors":[ { "firstSource":"12 ...

Retrieve information from Datatable Vuetify using axios fetch

I am encountering an issue with displaying data from a GET axios API. When inspecting the endpoint call, it correctly returns an array with objects. However, when attempting to display this data in the datatable, it shows that there is no data available. & ...

How can I retrieve HTML with JavaScript enabled?

Seeking to extract the HTML code from a webpage using PHP, I attempted the following: $url = 'http://en.wikipedia.org/wiki/New_York_City'; $html = file_get_html($url); However, an issue arose where Wikipedia failed to supply the <script> ...

Troubleshooting an Angular.js "Hello World" application that is malfunctioning

I've been trying to get a simple Hello World app working by following different tutorials, but it doesn't seem to be functioning correctly. I've double-checked my code and everything looks right to me. Could someone please assist me in troub ...

Comparing npm start and running the app with node app.js

I'm brand new to exploring the world of Node and understanding the basics of app development. I find it interesting how these two commands seem to have a similar output: node app.js --compared to-- npm start Both commands appear to continue "l ...

Utilizing hyperlinks within NicEdit content and managing events with jQuery

I am using nicEdit, a rich editor, on my website to insert hyperlinks into the content. While I can successfully add hyperlinks using the setContent() method after initializing nicEdit, I am facing issues with handling click events for hyperlinks that have ...

What is the best way to ensure synchronous function execution in Angular?

Consider the following scenario: ServiceA is accessed by two components with inputs. ComponentA contains a textArea while ComponentB has a toggle button. Whenever these components are changed, ServiceA.save() is triggered, which subsequently makes an HTTP ...

Unable to alter the state through the URL bar using ui-router

I am facing an issue where I get redirected to the home state whenever I try to directly access a URL like mysite.com/#!/about. My menu with ui-sref links is functioning correctly, but when it comes to nested states, I encounter problems switching betwee ...

Is there a way to restrict the number of checkboxes selected based on the values of radio buttons?

I am currently working with a group of radio buttons: <input type="radio" name="attending_days" value="06-18-13"/>Tuesday June 18, 2013 <input type="radio" name="attending_days" value="06-18-13"/>Wednesday June 19, 2013 <input type="radio" ...

What is the best way to transfer information from a ReactJS application to an Outlook Template?

I am facing a dilemma with integrating information from an Outlook template into the subject and body of an email. The data I need resides in the FrontEnd, which is developed using React and Javascript. I am uncertain if it's feasible to transfer the ...

use element ui tree and vue to filter files according to selected folder

Utilizing the element UI treeview to showcase folders. Each folder or its child folder contains files that need to be displayed based on folder selection. While it's easy to filter and list out these files in a normal list, I am facing challenges with ...

Getting values for parameters using .attr("action") using JavaScript/jQuery - a beginner's guide

In my Ruby On Rails application, I have a form that is rendered like this: <%= form_tag myaction_path(item_id: item.id), { class: 'myaction', id: "myaction_#{item.id}", ...

Leverage the power of Azure DevOps release variables group within a Vue application for

Recently, I found myself in possession of a project that was initially developed in Angular and successfully deployed to Azure DevOps. However, I have been tasked with creating a new version of the project, this time using Vue.js. The project functions per ...

Generate a random number using the Math.random() method in Node.js/JavaScript to access a folder on the local machine

I am facing a challenge in reading a JSON file located deep within multiple folders on my local machine. The issue arises because the folder name where the file is stored changes every time, as it is generated using the Math.random() method with the prefix ...

Update the content inside the extension by modifying its innerHTML

Just starting out with JavaScript, I'm attempting to create a basic extension that can generate a random number. document.getElementById("submit").onclick = function() { a = document.getElementById("in1").value; b = document.getElementById("in2 ...

Utilize Bootstrap's JavaScript feature to prevent form submissions when there are invalid fields present and to address any issues where the form is not functioning properly

Utilizing Bootstrap version 4, I have a contact form within index.php that requires user validation. Upon submission, users should be alerted to any missed required fields. For instance, if a user submits without completing any fields, they should see the ...

Leverage the power of Laravel's Blade.php templating engine by incorporating JavaScript code compiled with

How can I incorporate a JavaScript function in my blade.php file? I have created xyz.js with a simple function: function picture(something){ document.getElementById('idXYZ').src = "example.com"; } Next, I added this file to the webpack.mix. ...

Having trouble with clearing the text box while utilizing Page Methods in ASP.NET

I've been encountering some challenges with .net PageMethods. I have a text box and I want to clear it if the retrieved value from the database call is invalid or not in the table. Although I have a JavaScript function that displays a popup message, i ...

What is preventing my div from occupying the entire window space?

Currently, I am attempting to create a div that will occupy the entire height of the window, which is set to 640px, regardless of the content within the <h3> tag. However, I seem to be missing something in my code. I am using an emulator to run the ...

Modify the wording of the stock market text

Would greatly appreciate it if someone could assist me. I have a limited understanding of jquery/js and am facing difficulty in accomplishing this task. I am looking to change the text "Out of stock" to "In stock," but only when the key is "1." These tex ...