Vue 3 組合 api - 計算屬性傳回未定義
P粉662089521
P粉662089521 2023-10-31 19:00:10

使用 Vue 3 組合 API,如何傳回屬性 firstDigit 的計算值?計算屬性中的關鍵字thisundefined 但是當我將this 排除在外時,我收到錯誤fourDigits is not Defined

<script setup>
import { computed, reactive } from 'vue'

const input = reactive({
    fourDigits: Array(1,2,3,4),
    firstDigit: computed(() => {
      return this.fourDigits[0] <===== `this` is undefined but if I leave `this` out, then `fourDigits` is undefined.
    })
</script>

<template>
   <div>
     <pre>
       {{JSON.stringify(input.firstDigit, null, 2)}}
     </pre>
   </div>
</template>


#
P粉662089521
P粉662089521

全部回覆(2)
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!