我想構建和部署 Vue3 Typescript 應用程式。我正在使用 Vite,當我嘗試構建應用程式時出現錯誤。
vue-tsc --noEmit && vite build
error TS2322: Type '{ backgroundImage: string; }' is not assignable to type 'string'.46 :src="image"
我的 vue3 應用程式的檔案夾如下:
./spine-frontend
..../src
--------/assets
----------/img
--------/views
----/public
我正在嘗試將它用作我的影像作為資料:
<template>
<div class="absolute top-0 right-0 block w-9/12 h-full">
<img
alt="Snowy mountain lake"
class="object-cover min-w-full h-full"
<div class="absolute top-0 right-0 block w-9/12 h-full">
<img
alt="Snowy mountain lake"
class="object-cover min-w-full h-full"
:src="image"
/>
</div>
/>
</div>
</template>
<script lang="ts">
export default {
name: 'Home',
data() {
return {
image: { backgroundImage: "url(static/img/hero-image.jpg)" }
}
}
}
</script>
你能幫我在構建時使用 vue3/vite 的方式來渲染我的影像嗎?
謝謝
uj5u.com熱心網友回復:
您應該defineComponent在使用 TS 時使用,以便可以正確推斷型別
https://vuejs.org/guide/typescript/overview.html#definecomponent
另外,我看到您有一個名為 的組件Home,組件名稱應始終為多字:
https://vuejs.org/style-guide/rules-essential.html#use-multi-word-component-names
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/435402.html
