프로젝트/영화 검색 (Vue)

Vue 프로젝트 영화 포스터가 없는 경우 예외 처리

IT Blue 2021. 8. 17. 13:52

 

Vue 프로젝트 영화 포스터가 없는 경우 예외 처리

 

1. /src/components/MovieItem.vue 수정

- methods 수정

...
  methods: {
    async init() {
      const poster = this.movie.Poster 
      if (!poster || poster === 'N/A') {
        this.imageLoading = false
      } else {
        await this.$loadImage(poster)
        this.imageLoading = false
      }
    }
  }
...

 

2. /src/routes/Movie.vue 수정

- methods 수정

...
  methods: {
    requestDiffSizeImage(url, size = 700) {
      if (!url || url === 'N/A') {
        this.imageLoading = false
        return ''
      }      
      const src = url.replace('SX300', `SX${size}`)
      this.$loadImage(src)
        .then(() => {
          this.imageLoading = false
        })
      return src
    }
  }
...