[Vuejs]-Make content editable div get focus on button click

3👍

The attribute for content editable should not be content-editable="true", but instead contenteditable="true".

const App = {
  el: '#app',
  methods: {
    focusDiv() {
      this.$refs.test.focus()
    }
  }
}

const app = new Vue(App)
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>

<div id="app">
  <div contenteditable="true" ref="test">My Div</div>
  <button @click="focusDiv">Focus on div</button>
</div>

Leave a comment