vue3 修改数组索引方式修改数组内容能不能响应式测试

joken-前端工程师 / 2024-11-05 / 原文

<template>
  <div class='box'>
    {{ abc[0] }}
  </div>
</template>
<script lang='ts' setup>
import { ref, reactive, computed, onMounted, nextTick, PropType } from 'vue';

const abc = reactive(['a', 'b', 'c', 'd', 'e'])

setTimeout(() => {
  abc[0] = 'kslfjlskfdjs'
}, 2000)

</script>
<style lang='scss' scoped></style>

结论

经测试通过数组索引修改数组字内容,可以响应式