[Vuejs]-How can I select the input value after clicking on a button?

0๐Ÿ‘

<template>
  <div>
    <button @click="handleClick">CLick me </button>
    <input ref="myInputRef" v-model="msg" />
  </div>
</template>

<script setup>
import { ref } from 'vue';

const msg = ref('World');
const myInputRef = ref(null)

function handleClick() {
  if (myInputRef.value) {
    myInputRef.value.select();
  }
}
</script>

I believe this is how you can solve this issue: create a ref for the input element and call the .select() method to select the content.

Leave a comment