[Vuejs]-How to pass styles from computed to template

0👍

You have to pass a Javascript object to the style attribute.

For example, instead of returning "background-color:green", you should return {'background-color': 'green'}.

Inside a *.vue file, it looks like this :

<template>
  <div id="app" :style="styleApp">
    Hello
  </div>
</template>

<script>

export default {
  name: "App",
  computed: {
    styleApp: function () {
      return {
        'background-color': 'green'
      }
    }
  }
};
</script>

Leave a comment