Home > Software engineering >  vite vue TypeError: Cannot read properties of undefined (reading 'checkedNumbers')
vite vue TypeError: Cannot read properties of undefined (reading 'checkedNumbers')

Time:10-28

My template

<script setup>
import { computed, ref, watch } from "vue";
let checkedNumbers = ref([]);



function sum(){
  return this.checkedNumbers.reduce(function (a, b) {
    return parseFloat(a)  parseFloat(b);
  },0);
}
<span id="prixSum" >
        {{ prixSum = sum()== 0 ? model.prixS1 : parseFloat(sum()  model.prixS1).toFixed(2) }}

</span>
<ul>
  <li>
<span  >{{model.prixS1}} </span>

<input type="checkbox" id="model.prixS2" name="model.prixS2" v-model="checkedNumbers"
       :value="model.prixS2"   required>


<input type="checkbox" id="model.prixS3" name="model.prixS3" v-model="checkedNumbers"
       :value="model.prixS3"   required>

  </li>
</ul>

{{ prixSum = sum()== 0 ? model.prixS1 : parseFloat(sum() model.prixS1).toFixed(2) }}

{{model.prixS1}}


```

CodePudding user response:

ur using script setup, this is undefined, just use vars

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

// smth like `{ value: [] }`
let checkedNumbers = ref([]);

function sum(){
  return checkedNumbers.value.reduce(function (a, b) {
    return parseFloat(a)  parseFloat(b);
  },0);
}

  • Related