Encountered an error while using vue-tiny-slider: Uncaught TypeError in promise - t2 is not recognized as a function

I'm currently using Vue 3 and have installed the vue-tiny-slider library from https://github.com/viktorlarsson/vue-tiny-slider. However, I encountered an error stating 't2 is not a function'. Since the documentation doesn't provide instructions for setting up on Vue 3, I attempted to configure it myself.

Below is my template:

<template>
    <div class="my-slider">
        <vue-tiny-slider
            :mouse-drag="true"
            :loop="false"
            :items="2"
            :gutter="20">
            <div
                v-for="recipe in storeRecipe.popularRecipes"
                :key="recipe.recipe_id">
                <ItemCard :recipe="recipe" :pending="storeRecipe.pending" />
            </div>
        </vue-tiny-slider>
    </div>
</template>

And here is the script:

<script setup>
import ItemCard from '@/component/ItemCard.vue';
import { onMounted, h } from 'vue';
import { useStoreRecipe } from '@/store/storeRecipe';
const storeRecipe = useStoreRecipe();

import VueTinySlider from 'vue-tiny-slider';

const render = () => {
    return h(
        VueTinySlider,
        {},
        {
            default: () => (this.$slots.default ? this.$slots.default() : []),
        }
    );
};

onMounted(async () => {
    render();
    await storeRecipe.loadPopularRecipes();
});
</script>

If anyone has a potential solution, please share. Thank you!

Answer №1

To customize VueTinySlider, create a new .js file named tinyslider.js and modify the render code there. Then, import the updated slider into the Single File Components (SFCs) where you want to use it.

tinyslider.js

import { defineComponent, h } from 'vue'
import VueTinySlider from 'vue-tiny-slider'

export default defineComponent({
  extends: VueTinySlider,
  render() {
    return h('div', this.$slots?.default ? this.$slots.default() : {})
  }
})

Component.vue

<template>
  <div class="my-slider">
    <vue-tiny-slider :mouse-drag="true" :loop="false" :items="2" :gutter="20">
      <div v-for="recipe in storeRecipe.popularRecipes" :key="recipe.recipe_id">
        <ItemCard :recipe="recipe" :pending="storeRecipe.pending" />
      </div>
    </vue-tiny-slider>
  </div>
</template>
<script setup>
import VueTinySlider from './tinyslider.js'
import { onMounted } from 'vue';
import { useStoreRecipe } from '@/store/storeRecipe';
const storeRecipe = useStoreRecipe();

onMounted(async () => {
    await storeRecipe.loadPopularRecipes();
});
</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

Identify duplicate values in an array by comparing pairs of elements

If the array contains the data shown below: let array = [{ name: "Ramesh", SalseVersion: 10, MarketingCode: 11 }, { name: "Suresh", SalseVersion: 12, MarketingCode: 13 }, { name: "Siva", SalseVersion: 10, MarketingCode: 14 }, { na ...

Help! My ReactJS D3 scatter plot is malfunctioning when I hover over it. What could be causing this issue and how

Everything looks great with the visualization until I hover over one of the circles, then it breaks. Check out the visualization in Codepen This is the error shown in the console: Uncaught TypeError: d.Time.substring is not a function The issue seems to ...

Modifying vertices in THREE.LineSegment: Adding and deleting

I am facing an issue with a THREE.LineSegments object, where I need to dynamically change the number of vertices. However, when I try to modify the geometry vertices array, the lines with removed vertices remain in place. Is there a way to remove vertices ...

Creating 3D Impostors with spherical shapes in three.js

I am currently in the process of transitioning a native OpenGL application to WebGL using the three.js framework. One challenge I am encountering is implementing spherical impostors. Spherical Impostors consist of quads (or two triangles) that always face ...

The dropdown menu adjusts its value based on the selected radio button

When I select the "12 hour" radio button, the drop-down values change to 1 am - 12 am and 1 pm - 12 pm. If I select 24 hours, then the values change to 1-24. Below is my code: <script src="http://code.jquery.com/jquery-1.7.2.min.js"></script> ...

The play button in the customized React AudioPlayer may sometimes need to be tapped twice in order to start

I've encountered an issue with my simple audio player (React/Vite) that transitions to the next track automatically or manually. Everything seems to be functioning correctly except for the initial press of the play button. The player opens with the pa ...

Node.js is no longer able to fulfill promises

Imagine having an API that needs to be queried for important data. const fetchData = async () => { rootUrl = 'http://....' data = await (await fetch(rootUrl)).json() moreData = await Promise.all(data.map(async (elem) => subData = ...

Hmm, I seem to be encountering an error where res.sendStatus is not recognized as a function. What could be causing this

For the last few months, I have been immersed in Node.js/Express to create a REST Api. However, I've hit a roadblock with an async function in my controller.js file. The callback function is successfully receiving the client's request, but when i ...

Struggling to understand the concept of utilizing Promises for data retrieval

I'm currently facing an issue with my async function that awaits a GraphQL call. Even though the call returns a Promise containing the desired data, I'm struggling to access it effectively. Below is the snippet of code in question: export async ...

Notification box appearing at the lower part of the display

I have recently been given the task of updating my company's JavaScript alerts with more customizable bootbox alerts. After playing around with it, I managed to make an alert appear when a button is clicked, but the alert keeps showing up at the botto ...

Steps to create a continuous blinking/flickering effect on a highchart pathfill

I am currently utilizing highcharts within one of my applications. I want to emphasize a particular stroke based on the content, and while I have achieved this already, I now need it to blink or flicker as if indicating an issue at that specific point. C ...

Storing JSON data in list items within an HTML document using React

I am currently working on creating a component that can provide auto-suggested values from an online API and then send the value and its associated JSON data back to the parent component. So far, I have successfully implemented a feature that generates a ...

Choose between using a function as a parameter or an instruction when making a selection based on change

I am curious about the distinction between the following two sentences: $('#select').on('change', function() { Manager.doRequest(); }).trigger('change'); And these variations: $('#select').on('change&apos ...

What is the best way to display JSON data within a React component?

Is there a way to display JSON data in a react component by rendering each array as a separate unordered list? Here is the JSON Data: "value":{ "h3":[ "Best selling products", "Best Corporat ...

Break down React website into distinct modules and bundle them as npm dependencies within a single package

Currently, I am developing a React website that includes distinct sections such as contact management and message management. Each of these sections is quite extensive. To navigate to these sections, we use a single dashboard for control. Since separate ...

How can I use jQuery to choose and manipulate the text in my textbox within a repeater?

I am working with a repeater that contains textboxes populated with data from a database. During run-time, this repeater generates multiple textboxes with lots of data. <asp:Repeater ID="rpter" runat="server"> <ItemTemplate> <fieldset ...

Having trouble understanding why my submission button isn't working

I'm struggling to understand why my submit button isn't working correctly. Initially, I had an e.preventDefault() at the beginning and it didn't have any effect. However, after receiving advice from an instructor, I included it in the condit ...

Change not accepted

I am a beginner in Angular and still grappling with the fundamentals. On my menu, I have a cart icon with an initial value of 0 upon first load. In my product list, each product has an 'AddToCart' button. What I aim to achieve is- I want to dy ...

The never-ending scroll feature in Vue.js

For the component of cards in my project, I am trying to implement infinite scrolling with 3 cards per row. Upon reaching the end of the page, I intend to make an API call for the next page and display the subsequent set of cards. Below is my implementatio ...

Utilize the npm module directly in your codebase

I am seeking guidance on how to import the source code from vue-form-generator in order to make some modifications. As a newcomer to Node and Javascript, I am feeling quite lost. Can someone assist me with the necessary steps? Since my Vue project utilize ...