What is the best way to integrate an OpenSeadragon module into my Vue component?

I am working on incorporating an external JavaScript library, called "OpenSeadragon", into my Vue Component.

The main challenge I'm facing is figuring out how to properly load this library in my Vue component. In the parent template, I have included the library using:

<script src="{{ asset('js/openseadragon.min.js') }}"></script>

This snippet showcases my Vue TestComponent:

<template>
    <div>
        <div id="openseadragon" style="width: 100%; height: 600px; border: 1px solid red"></div>
    </div>
</template>

<script>

    export default {
        data(){
            return {

            }
        },
        created() {

           // The challenge remains on loading openseadragon effectively
            OpenSeadragon({
                id:              "openseadragon",
                prefixUrl:       "/openseadragon/images/",
                tileSources:     "/example-images/duomo/duomo.dzi"
            });


        },
        methods: {
            //
        }
    }
</script>

However, this implementation triggers the following error message:

[Vue warn]: Error in created hook: "TypeError: Cannot read property 'appendChild' of null"

Answer №1

Based on the information provided in the Vue Lifecycle, it is recommended to place your function call within the mounted hook.

This is because the element with the ID #openseadragon does not exist until after the mounted hook has been called.

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

Tips for resetting an RXJS scan operator depending on a different Observable

I created a component that triggers an onScrollEnd event once the last item in a virtual list is displayed. This event initiates a new API request to fetch the next page and combine it with the previous results using the scan operator. In addition, this c ...

How to retrieve and modify JSON data in Node.js using Stream with both Get and Post methods

Exploring Node.js for the first time, I'm currently tackling a project where I aim to utilize Request for streaming data from one endpoint to another. The objective is to leverage Request for extracting and posting an altered JSON body through a pipe ...

Learn the simple process of resetting a form with the input type reset functionality

Hello! This is my first time asking a question here, so please bear with me if I make any mistakes. I am attempting to reset a form using the input type=reset tag in HTML5, but I'm encountering some issues. I've included a snippet of my code bel ...

Directing JSON POST Request Data to View/Controller in a Node.js Application

Currently, I am working on a project hosted on a local server at http://localhost:3000/. This server receives a post request from another server in the following manner: return requestLib.post({ url: 'http://localhost:3000/test', timeout ...

Combining Option Value and Name Selection Using React Hooks

Currently, I am facing a situation where I need to retrieve two different values (item.id and item.name) to set the State when selecting an item from my dropdown menu. Right now, I am only able to do this for one value (item.id). Is it possible to achieve ...

Substitute the value in the object associated with a mystery key with a different value from the second object

I am dealing with the following objects: http ={" xxx": "#phone#","yyy": "1234", "zzz":5678 } input= {"phone": "2", "id": "258 }, Can someone help me find the #phone# val ...

Navigating TS errors when dealing with child components in Vue and Typescript

Recently, I encountered an issue where I created a custom class-based Vue component and wanted to access its methods and computed properties from a parent component. I found an example in the Vue Docs that seemed to address my problem (https://v2.vuejs.org ...

Using Javascript and JQuery to display the current date upon the initial page load, then preserving the date when navigating to different

When using Bootstrap's Datepicker, I encountered a scenario where I need the current page to load when a user first visits the page. However, if the user selects a different date and then navigates to another page, I want the Datepicker to retain the ...

Will the identifier "id" be considered unique if the element with the matching id has its display property set to "none"?

Imagine you have a DIV element in your document with the id "row". Now, if you add another DIV with the same id and change the display property of the first DIV to "none", does the id of the second DIV become unique? ...

How can you protect your webhook from unauthorized access?

I am looking to create a webhook that will update the status of a document in my collection, triggering additional events in the process. Router.route('/mandrill/invitation_sent', { where: 'server' }) .post(function () { var resp ...

Troubleshooting: Issue with jQuery Ajax not receiving JSON response

Here is the JavaScript code I am using: $.ajax({ url: 'CheckColorPrice.php', type: 'POST', data: { url: '<? ...

locating the truth value of the data in an array retrieved from MongoDB

When returning from the mongoose find() function, I need to ensure that is_reqestor = true is checked. However, when updating the document, I pass the id which needs to be updated. let filter = { is_reqestor: true } if (!is ...

Unable to display content within a map function

I am facing an issue with a map function in my code. The function is supposed to return a component with deconstructed properties. While the map itself is functioning correctly and I can see all the right values when I log them to the console, nothing is g ...

Using an array as a reference can lead to failure when dealing with asynchronous calls

As I delve into referencing a document in MongoDB, my process involves first creating the document to insert before interfacing with the database itself. Upon initial setup: const venues = [ new Venue({ name: 'A' }), ]; const events = [ new ...

Struggling with jquery ajax and datatables

I am facing an issue with utilizing jQuery ajax to fetch data from a PHP file. The PHP file generates a table based on a database query. My intention was to apply datatables styling to the returned table in the HTML page, but unfortunately, this approach i ...

Generating a new POST header

I have encountered a challenge: I need to transfer an array to another page without using AJAX. My goal is to either redirect the user to the new page or open a popup displaying the new page, all while ensuring the array data is sent via a POST request. C ...

remove function erases all the data in Vue

My goal is to delete only the item that has been clicked on. todoList Component: template : <ul class="list-group"> <todo v-for="(todo,i) in todo" :key="i" :todoString="todo.todoString" : ...

Determining the final value of the last handle in a jQuery UI slider with multiple sliders present

I need help retrieving the first and last handle values from a jQuery UI range slider when there are multiple sliders on the page. Currently, my code is set up to grab the last value from the last slider's last handle. I attempted to address this by u ...

Pinterest's "Pin it" button causing issues with the 'back' function in Internet Explorer

Recently, I discovered a problem with the "Pin it" button for Pinterest in Internet Explorer (v9 at least). It seems that this button is causing issues with the 'back' functionality in the browser. When right-clicking on it, an entry like '& ...

Angular does not wait for the backend service call response in tap

Does anyone have a solution for subscribing to responses when the tap operator is used in a service? edit(status) { dataObj.val = status; // call post service with status.. this.service .update(dataObj) .pipe(takeUntil(this._n ...