vue3.2x use <script setup>, Build does not resolve computed properties in :src="require()"

Viewed 100

vue 3.2.31 use <script setup>

  <template>
    <img :src="require(`@/assets/images/icon_num_${state.lotteryNum}.png`)" alt="" />
</template>
<script setup lang="ts">
import {reactive} from 'vue'
const state = reactive({
    lotteryNum:1,
})
</script>

When running locally, there is no problem. But after packaging, the console will report an error when running online.

enter image description here

error message: ReferenceError: _unref is not defined

I tried not to use <script setup>,There is no problem with running locally, and there is no problem with running after packaging。

1 Answers

try this way like <img :src="require('@/assets/images/icon_num_'+state.lotteryNum+'.png')" alt="" />

Related