Search code examples
vue.jscomputed-properties

Vue warn invalid value from option expected an object but got function


I'm trying to bind a computed function to my style. And in this computed function I'm using a property. But Vue gives me the error that it expects an object but gets a function. This is my code.

<template>
  <div id="banner" :style="extractImageURL">

  </div>
</template>

<script>
export default {
    props: ['imageURL'],
    computed(){
      extractImageURL()
      {
        return "background-image: url(" + this.imageURL + ");"
      }
    }
}
</script>

Solution

  • this format:

    computed:{
      extractImageURL: function()
      {
        return "background-image: url(" + this.imageURL + ");"
      }
    }
    

    Vuejs computed guide