Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

this.$refs.name.select() function not found in vue

I am using Vue refs in my application so that in click a button some text will be select and copy. So I am using like

//In template
<input type="text" ref="url" value="my url"/>
<button @click="copylink">Copy Link</button>


//in methods
copylink() {
    this.$refs.url.select()
}

that is undefined.

But Using

document.querySelector('input').select()
I can select that.

My question is it possible all document methods using $refs. How do you do this?

like image 855
Shahadat Hossain Avatar asked Aug 11 '26 06:08

Shahadat Hossain


1 Answers

If you do console.log(this.$refs.url) it will give you back an array type result. All you have to do is: this.$refs.url[0].select() and it will work.

Let me know.

like image 51
cat_codes Avatar answered Aug 12 '26 20:08

cat_codes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!