簡體   English   中英

當我嘗試在 vue3 打字稿中執行內聯三元運算符時,出現“布爾類型上不存在屬性類型”錯誤

[英]i Get a "Property type does not exist on type boolean" error when i try to do an inline ternary operator in vue3 typescript

錯誤Property type does not exist on type boolean顯示在 show.value boolean

當我嘗試根據真實性為圖標應用文本時

<template>

<div class="d-flex cursor-pointer justify-content-between border rounded bg-white mt-4 p-2 w-100 " @click="dropdown">
    <span>Purchase Requsition</span>
    <span class="material-icons fs-28 text-primary">
{{show.value ? 'arrow_circle_down' : 'arrow_circle_down' }}     </span>
</div>

</template>

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

const show = ref<boolean>(false)

function dropdown(){
   show.value = !show.value
}
</script>

<style scoped>

</style>

您應該在模板中使用show而不是show.value show.value僅在組合 API 的script標記中可用。

<template>

<div class="d-flex cursor-pointer justify-content-between border rounded bg-white mt-4 p-2 w-100 " @click="dropdown">
    <span>Purchase Requsition</span>
    <span class="material-icons fs-28 text-primary">
      {{show ? 'arrow_circle_down' : 'arrow_circle_down' }}
    </span>
</div>

</template>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM