The vue-pdf is having trouble loading all pages due to an "undefined property" issue

I am currently utilizing the following technologies:

  • Vue.js, vue-route, Vuetify, Firebase (with a database) and vue-pdf

The issue I am facing involves attempting to load all pdf pages using "vue-pdf" plugin. However, when trying to read the pdf, I encounter the following error:

Uncaught TypeError: Cannot read property 'novel' of undefined

In my code, I have an object called novel, which is initially set to null. After fetching data from Firebase, this novel object gets populated. I referred to a tutorial here for loading multiple pdf pages, but while the tutorial uses a direct URL, I need to access a specific value in my object - "this.novel.nove_url". I'm uncertain about what mistake I might have made in implementing this. Below is the relevant portion of my code. Any assistance would be greatly appreciated.

<!-- Code goes here -->

Answer №1

When working with Vue.js, it's important to note that you cannot utilize this outside of the export default block. Additionally, keep in mind that Firebase database fetch operations are asynchronous, meaning the novel property will only be populated once the promise returned by get() is fulfilled (typically within the callback functions passed to the then() method).

To properly initialize the loadingTask variable, you can do so within the created() hook or inside get().then(). Here is a possible implementation (although untested):

import Footer from "./Footer";
import pdf from "vue-pdf";
import db from "../db";

export default {
  name: "Read",
  components: {
    Navbar,
    Footer,
    pdf,
  },
  data() {
    return {
      novel: null, // data from Firebase saved here
      src: null ,
      currentPage: 0,
      pageCount: 0,
      numPages: undefined,
    };
  },
  mounted() {
    this.src.promise.then((pdf) => {
      this.numPages = pdf.numPages;
    });
  },
  created() {
    let ref = db
      .collection("Novels")
      .where("novel_slug", "==", this.$route.params.novel_slug);
    ref.get().then((snapshot) => {
      snapshot.forEach((doc) => {
        this.novel = doc.data();
        this.novel.id = doc.id;
      });
      this.src = pdf.createLoadingTask(this.novel.novel_url); 
    });
  },
};
</script>

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

Utilizing Additional Parameters in Vuetify Rule Declarations

I am looking to establish a set of rules that can be applied universally across all fields. In order to achieve this, I need the ability to include additional parameters in my rules, such as setting a maxlength of 20 for one field and a maxlength of 50 f ...

I've encountered some issues with importing pagination from modules after installing SwiperJs

Having some issues with importing pagination from modules in SwiperJs for my nextjs project. The error message "Module not found: Package path ./modules is not exported from package" keeps popping up. I have tried updating the module to the latest version ...

Leveraging React Native to position a view absolutely in the center of the screen without obstructing any other components

How can I center an image inside a view in the middle of the screen using position: "absolute"? The issue is that the view takes up 100% of the width and height of the screen, causing all components underneath it (such as input fields and buttons ...

The issue of actions failing to flow from sagas to reducers in React.js

Upon user login, the success response is received but the action is not passed to the reducer. Strangely, during user registration, everything works smoothly. //saga.js import { put, takeEvery, all, call } from 'redux-saga/effects'; import {getRe ...

Node.js equivalent of Java's byteArray

I have a Node.js REST API with images being sent from a Java application as byte arrays. Here is an image Below is the string representation of the image in byte array form: [B@c75af72 I need to decode this byte array to verify if it is indeed an ima ...

unable to connect a value with the radio button

I am struggling to incorporate a radio group within a list of items. I am facing difficulty in setting the radio button as checked based on the value provided. Can anyone provide me with some guidance? Here is the HTML code snippet: <div *ngFor=" ...

Newbie in PHP: Techniques for transferring PHP variables between different sections of PHP code

In my project, I have a file named index.php which is responsible for uploading files to the server and setting PHP variables such as $target_folder_and_file_name. This index.php file also includes the following line (originally it was in an index.html fi ...

Create the key's value in a dynamic manner within localforage

When utilizing localForage to store data offline, I encountered an issue with generating unique key values for each form submission. My goal is to have the key value generated dynamically as 'activity_1', 'activity_2', 'activity_3& ...

Retrieving information from a dynamically generated HTML table using PHP

I have successfully implemented functionality using JavaScript to dynamically add new rows to a table. However, I am facing a challenge in accessing the data from these dynamically created rows in PHP for database insertion. Below, you will find the HTML ...

Show specific content based on which button is selected in HTML

I am working on a project where I have three buttons in HTML - orders, products, and supplier. The goal is to display different content based on which button the user clicks: orders, products, or supplier information. function showData(parameter){ i ...

Caution: Attempting to access a non-existent 'sequelize' property within a circular dependency in the module exports

Issue Nodemon server.js [nodemon] 2.0.15 [nodemon] to restart at any time, enter `rs` [nodemon] watching path(s): *.* [nodemon] watching extensions: js,mjs,json [nodemon] starting `node server.js` Warning: connect.session() MemoryStore is not designe ...

Personalized text field in date selector using Material UI

Hey there, I've been incorporating Material UI into my react project, specifically utilizing their recommended Material UI Pickers for a date picker. In order to maintain consistency with the rest of my form fields, I'm attempting to customize th ...

Updating a webpage using Ajax in Django

I've been diving into Django and am eager to implement ajax functionality. I've looked up some examples, but seem to be facing a problem. I want to display all posts by clicking on a link with the site's name. Here's my view: def archi ...

Both IE and Firefox exhibit erratic behavior when updating the location.hash during the scroll event

In my current project, I am experiencing difficulties updating the location.hash based on which div is currently active in a website with long scrolling. Surprisingly, this functionality works perfectly in Chrome, but fails to work in Firefox and IE. I h ...

Trouble fetching asynchronous data in Next.js Higher Order Component

Currently, I am in the process of creating a Higher Order Component (HOC) that will fetch user data from my API and then provide props to the wrapped component. This will allow the component to redirect the user based on their role. Although the HOC appea ...

Utilizing TypeScript to Populate an observableArray in KnockoutJS

Is there a way to populate an observableArray in KnockoutJS using TypeScript? My ViewModel is defined as a class. In the absence of TypeScript, I would typically load the data using $.getJSON(); and then map it accordingly. function ViewModel() { var ...

Tips for testing nested HTTP calls in unit tests

I am currently in the process of unit testing a function that looks like this: async fetchGreatHouseByName(name: string) { const [house] = await this.httpGetHouseByName(name); const currentLord = house.currentLord ? house.currentLord : '957'; ...

Making an Ajax call using slash-separated parameters

Handling APIs that require slash-separated parameters in the URL can be quite tricky. Take for example: http://example.com/api/get_nearest_places/:en_type_id/:longitude/:latitude One way to build this URL is by concatenating strings like so: var longitu ...

creating reactive images with Vue

The original code utilized an image in a menu as shown below: <img :alt="$t('more')" class="mobile-plus-content visible-xs" src="../../../assets/img/plus79.png" /> This results in: src="data:image/png;base64,the image" I made a mo ...

Creating beautiful prints with images

I have been tasked with developing an MVC C# application where the contents of a div are dynamically created using an AJAX call to fetch data from a database. Upon successful retrieval, the content is then displayed as a success message in JavaScript. Here ...