[Vuejs]-How to select a tag from app in a components or views?

0👍

Use v-model and a watcher like this: (live example)

<script>
export default {
    data () {
      return {
        colorInput: undefined
      }
    },
    watch: {
      colorInput(color) {
        document.body.style.backgroundColor = color
        localStorage.setItem("background", color)
      }
    },
    created() {
      this.colorInput = localStorage.getItem("background")
    }
}
</script>

<template>
  <input type="color" v-model="colorInput">
</template>

Leave a comment