0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ボタンをクリックして、v-bindで画像を切り替える(Vue3)

Posted at

v-bindで画像を切り替えようとしたらできない。なんでや。。。

メモ書き
***

画像の格納先をassetではなく、publicに置いたらできた。

index.vue
<template>
  <img :src="Img">
  <button @click="changeImg">変われ</button>
</template>

<script setup lang="ts">
import { ref } from 'vue'
// 画像はassetではなく、publicに置く
const Img = ref<any>('/first.svg')
const changeImg = () => {
  Img.value = '/second.svg';
}
</script>

***
これでもいけるかも

index.vue
<script setup lang="ts">
import firstImg from '../../asset/first.svg'
import secondImg from '../../asset/second.svg'

</script>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?