[Vuejs]-Javascript + Vue: array failing to be reactive

1๐Ÿ‘

โœ…

I did a sandbox with the fix: https://codesandbox.io/s/beautiful-pond-8jg5zw?file=/src/App.vuee

<template>
  <button @click="entries.push(3)">Press me!</button>
  <ul>
    <li v-for="entry in entries" :key="entry">
      {{ entry }}
    </li>
  </ul>
</template>

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

const entries = ref([1, 2]);
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>

Use the import { ref } from "vue";

Tip: Be aware of the difference between Ref and Reactive

https://vuejs.org/guide/essentials/reactivity-fundamentals.html#ref

Leave a comment