Insert character at Cursor position in VUE JS

后端 未结 3 1602
小蘑菇
小蘑菇 2021-02-03 10:42

I have been trying to insert emoji in textarea exactly where the cursor is at. I looked around how tos in the web could not find anything specific in VUE JS. Most o

3条回答
  •  我在风中等你
    2021-02-03 11:17

    Two steps:

    1 get textarea element using a vue-way:

    1.1 Add ref attrbute to textarea tag in your template code:

    
    

    1.2 get this element after mounted hook of this component:

    let textarea = this.$refs.ta
    

    2 get cursor position of textarea element.

    let cursorPosition = textarea.selectionStart
    

    Here is reference: ref

提交回复
热议问题