ts+v3 報錯 Property 'title' does not exist on type 'never'


使用TypeScript開發 vue3 項目,開發中用for循環渲染UI時,出現這個錯誤是因為Typescript在執行代碼檢查時在該對象沒有定義相應屬性。

我們可以通過字符方式獲取對象屬性

<el-collapse v-model="activeName" :accordion="accordion">
        <el-collapse-item
          :title="item['title']"
          :name="index + 1"
          v-for="(item, index) in state.imgList"
          :key="index"
        >
          <div class="img" v-for="(item2, index2) in item['list']" :key="index2">
            <img :src="item2" :title="`${item2}號圖片暫時無法展示`" alt="" />
            <div class="text mt-5">
              {{ item2 }}
              <badge
                class="ml-5"
                bgColor="rgb(166, 177, 246)"
                text="復制"
                @click="copyImgAddress(item2)"
              ></badge>
            </div>
          </div>
        </el-collapse-item>
      </el-collapse>

完成


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM