I want to create computational properties for 2D arrays with Vue's computed

Asked 1 years ago, Updated 1 years ago, 332 views

I am currently practicing Vue3 code (Composition API).
The purpose is to find the product (only practice) in the calculation properties if there is an array similar to the following:I just don't know how to write "computed".I would like the items to be returned to the hoge.Thank you for your cooperation.

<script>
export default {
  data(){
    US>return{
        items: [10,20], [20,30], [25,34]
    }
    },
  computed: {
    multiply(){   
      return 'hoge';
  },
}
}
</script>

<template>
    <lib-for="item in items">
    {{ item}}-{{multiple}}
    </li>
</template>

javascript vuejs

2023-02-21 21:12

1 Answers

The Composition API is the <script setup> portion of the code below. The same is done in the Composition and Options APIs.
(Variables are different)

Note: What is the Composition API?

<script setup>
import {computed, ref} from "vue";

const vals=ref([10,20],[20,30],[25,34]])
const multi=computed(()=>{
  return values.value.map([x,y])=>x*y)
})
</script>

<script>
export default {
  data(){
    US>return{
        items: [10,20], [20,30], [25,34]
    }
  },
  computed: {
    multiply(){   
      return this.items.map([x,y])=>x*y)
    }
  },
}
</script>

<template>
    <lib-for="(item,idx)in items">
    {{ item}}-{{multiple [idx] }}
     ↔
    {{vals[idx]}} {{multi[idx] }}
    </li>
</template>


2023-02-21 21:19

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.