Recursive Vue components can be implemented using typescript, allowing for

I am working on a TypeScript component that utilizes recursion:

<template>
  <div :style="{ paddingLeft: depth * 20 + 'px' }">
    <h1>Level {{ depth }}</h1>
    <div v-if="depth < 2">
      <Recursive v-for="i in 3" :key="i" :depth="depth + 1"/>
    </div>
  </div>
</template>

<script lang="ts">
import * as Vue from "vue";
import { Component, Prop } from "vue-property-decorator";

@Component({
  components: { Recursive }
})
class Recursive extends Vue {
  @Prop({ required: true })
  depth!: number;
}

export default Recursive;
</script>

Check out the demo: https://codesandbox.io/s/vue-typescript-recursive-12u3q?file=/src/components/Recursive.vue

During development, the recursion works without any issues.

However, after building the project, recursive imports are converted to the following strings:

<!--function(e,n,r,o){return ln(t,e,n,r,o,!true)}-->
rather than HTML elements.

I am seeking advice on how to ensure the recursion functions properly after building the project.

Answer №1

I made a mistake by not specifying the name of the component in the @Component decorator:

@Component({
  name: 'Recursive',
  components: { Recursive }
})

Fortunately, this code is functional in both development and compiled modes.

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

Setting input limits in AlertBox in Ionic v3: A step-by-step guide

I am currently working on creating an alert box that includes some inputs. I am trying to restrict the input to a maximum of 10 characters and ensure that only numbers are allowed. Unfortunately, I haven't been able to find any helpful guides on this ...

Option to publish Docker images

I'm currently trying to set up a Vue app locally inside a Docker container, but I'm facing an issue when it comes to accessing the specified port. Below is my Dockerfile: FROM node:lts-alpine RUN mkdir -p /app COPY . /app WORKDIR /app RUN npm ...

The program encountered an unexpected identifier 'getProject' instead of ';'. It was expecting to find a semicolon after the async variable declaration

When using this JavaScript on a webpage, I encounter an issue: <script async type="module"> import {projectCode} from "./assets/js/config.js"; import {getProject} from "./assets/js/saleproject.js"; import {getAccount} fr ...

Troubleshooting ReactJs in Chrome during page load: encountering issues with undefined properties when utilizing the console

When debugging React on initial page load, I encounter a problem. Upon hovering over this, I can see the content, but using the console shows that this is undefined. Interestingly, this issue only arises when I refresh the page; clicking around does not tr ...

What is the most effective method for sharing a form across various components in Angular 5?

I have a primary form within a service named "MainService" (the actual form is much lengthier). Here is an overview- export class MainService { this.mainForm = this.formBuilder.group({ A: ['', Validators.required], B: & ...

The vue template is indicating an error related to unused variables according to the eslint rule vue/no

Perhaps this information will come in handy for someone. I am working with a Vue template that contains HTML. <template slot="HEAD_Status" slot-scope="data"> <!-- some html without using of data --> </template> Eslint is showing [v ...

CoursesComponent does not contain a Directive annotation

I have been following a tutorial online at this link: https://www.youtube.com/watch?v=_-CD_5YhJTA Unfortunately, I keep encountering the following error message: EXCEPTION: No Directive annotation found on CoursesComponent Here is an excerpt from my a ...

The context of the Nuxt.js3 plugin loses its definition

Currently, I am working on a project that involves Nuxt.js3 and supabase integration. In my plugins/supabase.server.js file (I am still unsure whether using server or client is the best approach), I want to call "supabase = createClient(~~)" from index.vu ...

Filtering Array Elements in Vue JS: A Step-by-Step Guide

In my Vue Js 2.0 application, I am working on filtering elements in an array format. Here is the code snippet: const search = this.search_by_name.toLowerCase() const searchContact = this.search_by_contact.toLowerCase() return this.meetings .map(i => ...

Experiencing TypeScript error in VSCode while trying to run in Nodejs? Here's how to troubleshoot and resolve

Experimenting with the performance measurement code provided by Nodejs in VSCode has been an interesting challenge for me. I encountered no issues running the code in Nodejs, and it executed smoothly. However, when attempting to run the code in VSCode, er ...

Troubleshooting: Inability to use the v-html attribute in VueJS

Currently, I am facing a situation where I need to replace a link within a paragraph element using v-html. Here is the code snippet for reference: <p v-html="websiteHTML"></p> The variable websiteHTML contains the following HTML code: <a ...

Preventing submission with @submit is not functioning as expected on a Vue MD-

Whenever I click the 'login button' without filling data into the md-input, it still proceeds. I tested my onSubmit() method by logging in with my user and it worked! I believe the issue lies with my form rather than the method itself. Here is t ...

Converting docx files to PDF in Angular 15 using the "docxjs" library: A step-by-step guide

I am currently utilizing the to generate some docx files and enable downloading, but I am faced with the challenge of converting these files into PDF format. This is my current process: public download(data: any): void { const documentCreator = new D ...

I find it frustrating to constantly remove node_modules and reinstall the packages just to get npm run prod to function properly

Encountering this issue repeatedly: $ npm run production @ production /var/www/html/**** cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js xnpm ERR! ...

Angular 6: The Promise<any> is incompatible with the LeagueTable type

Recently delving into Angular and attempting to retrieve JSON League Table data from the API, I encountered an error message stating Type 'Promise' is not assignable to type 'LeagueTable'. leaguetable.service.ts import { Injectable } ...

How can you align the label of a v-text-field to the right in rtl languages?

I am working with a v-text-field in the following format: <v-text-field v-model="username" label="نام کاربری" /> However, I have noticed that the label appears on the left side. Is there a way to adjust it so that it displays on the right ...

Exploring the potential of lazy loading with AngularJS 2 RC5 ngModule

I am currently utilizing the RC5 ngModule in my Angular project. In my app.module.ts file, the import statements and module setup are as follows: import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/plat ...

What methods can be used to configure Jasmine to read individual Vue component files?

I recently installed Jasmine and Vue through npm, but I'm encountering an issue when trying to import the Vue component itself, which is a .vue file. It seems to be having trouble reading the template section enclosed within <template></templ ...

How to specify the return type of a promise from an observer in Angular 6

Typically, I prefer using observables. However, in order to avoid 'callback hell' in this particular scenario, I decided to use toPromise(). Unfortunately, I encountered a lint error message when trying to define the return type: The 'Obj ...

Tips on transforming current JSON into an alternate JSON format

Using React with TypeScript, I have a JSON data set of employees categorized by their department. Here's a snippet of the JSON data: [ { "department": 1, "name": "Test", "age": 32, "contact": 242222120, "id": 1 }, { "department": 1, "name": "Te ...