Without specifying an element, the Vue3 Composition API PerfectScrollbar Plugin cannot be initialized

I'm currently facing an issue while developing a Vue3 Perfect Scrollbar plugin. The problem arises when I try to initialize the object, resulting in the following error:

Error: no element is specified to initialize PerfectScrollbar

The code for the Scrollbar component is as follows:

import PerfectScrollbar from 'perfect-scrollbar'
import { isEmpty } from 'lodash'
import {
 onMounted,
 reactive,
 ref,
 h
} from 'vue'

export default {
  name: 'VuePerfectScrollbar',
  props: {
    options: {
      type: Object,
      required: false,
      default: () => {
      }
    },
    tag: {
      type: String,
      required: false,
      default: 'div'
    }
  },
  setup(props, {emit, slots}) {
    const el = ref(null)
    let ps = reactive({})
    
    onMounted(() => {
      if (isEmpty(ps)) {
        ps = new PerfectScrollbar(el, props.options)

      }
    })


    return () => h(
      props.tag,
      {
        class: 'ps',
        ref: el
      },
      slots.default && slots.default()
    )
  }
}

Prior to initializing, I verified the existence of the element reference through a console.log statement. Surprisingly, the element reference was present which makes me wonder why the error is still occurring. The insight provided by this source suggests that

This error simply means that you are calling PerfectScrollbar on something that doesn't exist!
. Could it be possible that the DOM has not been updated at that point? I even tried using nextTick but unfortunately, it did not resolve the issue.

Answer №1

To obtain the `value` attribute in the ref property, use the following code snippet :

const scroll = new CustomScrollbar(el.value, options)

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

Is your Laravel 9 and Inertia app experiencing a CSRF issue resulting in a 419 error message indicating that the page has expired

Whenever I attempt to utilize a delete route after deploying, an error message is displayed: 419 | PAGE EXPIRED Failed to load resource: the server responded with a status of 419 () The function within the Vue component responsible for triggering the rout ...

A guide on integrating CKEditor's simple upload adapter and resolving the CKEditor error in Vue.js: CKEditorError - duplicated modules

Looking to enhance my Vue project with CKEditor functionality, I successfully integrated the editor but now wish to enable image uploads within the text area. Despite using the simple upload adapter as outlined below, the page displaying the editor is no ...

Save the outcome of the apollo query in a local state?

Imagine having a collection of condensed items associated with user IDs. When clicked, I aim to asynchronously fetch and display additional data using an Apollo query - like username, address, etc. How can I effectively "cache" or store this information lo ...

How can I send data to components that are dynamically added?

Recently, I put together a test on a codepen that allows me to dynamically add components to an existing page. However, the challenge lies in passing props to these components. While browsing through another question, I found someone else struggling with a ...

What is the best way to connect data so that when a user clicks on a specific card, it appears on a popup card

When a user clicks on any card containing data retrieved from a backend API GET method, that data should be displayed in a pop-up card. In my situation, I have two components: DisplayNotes.vue and UpdateNotes.vue. Whenever a user clicks on a displayed card ...

Add an item with a combination of different data types (such as objects and arrays) to a Mongo database, but encountering

I am currently working on posting an item to MongoDB using a combination of Node.js, Express, Mongoose, and Vue.js. The item I am trying to post consists of a mix of objects and arrays. Although the object post is successful in generating an ID, the data i ...

Rotate image in Vue3 using @click

I have a dashboard with a refresh button that I want to rotate 360 degrees every time it is clicked. How can I achieve this rotation effect on the image with each click of the refresh button? Below is the code snippet I have been working on, but it only r ...

Issue: The vue-loader module needs @vue/compiler-sfc to be included in the dependency tree

Encountering an issue while attempting to execute the following command: npm run serve I have attempted to resolve this by running npm update and sudo npm serve, without success. Additionally, deleting the package-lock.json file and then running npm insta ...

VueJS and Vite: Encountering an unexpected character '�' while attempting to import files that are not JavaScript. Keep in mind that plugins are required for importing such files

I'm puzzled by the error message I'm receiving: [commonjs--resolver] Unexpected character '�' (Note that you need plugins to import files that are not JavaScript) file: /..../..../WebProjects/..../ProjectName/node_modules/fsevents/fse ...

Seeking instructions on incorporating multiple components in a tab section effectively?

I am currently using a tab system that functions flawlessly. As I delve into learning VueJs, one concern has arisen in my mind about components and/or templates: Using the analogy of tab windows, how can I incorporate two components within a single tab, s ...

The Vuetify VSelect component displays a blank comment in the DOM instead of the expected rendering

Incorporating vuetify into my project has been a success overall. The components like v-file-input and v-text-field are functioning properly. However, I am encountering an issue with v-select as it is not showing up as expected. Instead, something unusual ...

Issue with Vue.js webpack encountering problems when importing a CSS file from an external library

I'm in the process of integrating the aos animation library into my testing app. I installed it using yarn add aos, and in my Vue application, I've included the following code: <script> .... import AOS from 'aos/dist/aos.js' imp ...

Utilizing v-if and splice on users to select items from v-model

After following a tutorial, I have the code snippet below that I would like to enhance: <div style="margin-top: 10px;"> v-for="task in taskItems" :key="task.id" <q-icon :name="task.icon"/> <div ...

Incorporating VueJS into a complex WebForms project with multiple pages

I'm currently working on a webforms project and I would like to incorporate VueJS into it. However, I am facing challenges when trying to set up the root element. If I enclose my content within a <div id="app"></div> element and specify t ...

Error: Unable to access 'isCE' property of null - Custom Component Library

Struggling to create a custom component library for Vue 3 using ViteJS and NPM. Here is a breakdown of my setup, can someone guide me in the right direction as I have hit a roadblock for the past couple of days. Here's how my files are structured: d ...

When executing `npm run start`, a blank page appears exclusively on the server

I recently set up a Vue landing page on my Mac. In the terminal, I navigated to the folder and executed "npm install" and "npm run dev", which ran without any issues. However, when trying to do the same on a managed server, I encountered challenges with t ...

Vue.js 3 with TypeScript is throwing an error: "Module 'xxxxxx' cannot be located, or its corresponding type declarations are missing."

I developed a pagination plugin using Vue JS 2, but encountered an error when trying to integrate it into a project that uses Vue 3 with TypeScript. The error message displayed is 'Cannot find module 'l-pagination' or its corresponding type ...

There was an issue with the rendering: "TypeError: Unable to access the property 'text' because it is undefined"

There is an issue when it comes to rendering the content.link.text property in this code. It shows a Error in render: "TypeError: Cannot read property 'text' of undefined", although there are no errors when passing the title and description. Par ...

Using Vue.js: Passing an object from data() to a mounted() function

I'm facing an issue while attempting to pass the grid array to the createGridChart. An error message stating "grid is not defined" keeps popping up: “grid is not defined”. export default { data() { return { grid: [], } ...

VueJs and Vuetify come together in perfect harmony in the V-select outlined component

I am new to using VueJS and Vuetify. I have noticed that with v-select outlined, the label is not directly on the border of the field. Instead, I have to click in the field first before it appears. Can anyone explain why this is happening? Here is my code ...