Dmitry
Dmitry

Reputation: 741

Vue typescript recursive component

I have a simple typescript component with 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>

Demo: https://codesandbox.io/s/vue-typescript-recursive-12u3q?file=/src/components/Recursive.vue

It works fine in development mode.

But once I make a build - recursive imports will be compiled into these kind of strings:

<!--function(e,n,r,o){return ln(t,e,n,r,o,!0)}--> instead of html.

What should I do to make the recursion work properly?

Upvotes: 3

Views: 1609

Answers (1)

Dmitry
Dmitry

Reputation: 741

I forgot to set the name of the component in @Component decorator:

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

This code will be working both in development and compiled modes.

Upvotes: 5

Related Questions