[Vuejs]-V-bind:style with array entry

0๐Ÿ‘

<!-- begin snippet: js hide: false console: true babel: false -->
<template>
  <p v-bind:style="backgroundColorFunc(2)">Lorem ipsum</p>
</template>

<script>
  export default {
    data() {
      return {
        arrayElem: ["ใ“ใ‚Œ", "This", "pronoun"],
      };
    },
    computed: {
      backgroundColorFunc: function(index){
        return {
          backgroundColor: this.arrayElem[index],
        };
      }
    };
  }
</script>

Leave a comment