相关文章推荐
忐忑的镜子  ·  C# ...·  9 月前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

im trying to do a v-for loop but its showing this error on vue3 + typescript project

this is a component and im passing props like this

<script setup lang="ts">
import { ref } from "vue"
defineProps({
  margin: {
    type: Number,
    default: 1
  futurecashflow: {
    type: Array,
    default: [1,2]
</script>

i tried everything, this error wasnt present before like a week ago this is apperaing out of no where

Since you're using TypeScript, you should use the TypeScript-only features. Define an interface of your props, then add the defaults with withDefaults:

interface Props {
    margin: number;
    futurecashflow: number[];
const props = withDefaults(defineProps<Props>(), {
    margin: 1,
    futurecashflow: [1, 2],

I fixed it by adding the props and then calling props.futurecashflow

import {ref,defineProps} from "vue"
let props= defineProps({
  margin: {
    type: Number,
    default: 1
  discountrate: {
    type: Number,
    default: 1
  futurecashflow: {
    default: [1,2]

and callingon v-for like

<tbody class="table-auto" v-for="(item, index) in props.futurecashflow">
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.