20
12

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 5 years have passed since last update.

Vue.jsでbackground-imageを指定する

Posted at

ちょっと手間取ったのでメモ

API叩いて画像のURLを取得・表示するサンプル抜粋

<template>
  <div v-if="image_src">
    <!-- ここ! -->
    <div :style="{ backgroundImage: 'url(' + image_src.url + ')' }"></div>
  </div>
  <div v-else>
    <p>no image</p>
  </div>
</template>

<script>
export default {
  computed: {
    image_src(){return this.$store.state.image.url}
  },
}
</script>
20
12
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
20
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?