想要实现的功能:点击按钮,在光标停留的地方,插入一段文案:
实现效果-插入文案为'{test}'.png
<el-input @blur="testBlur" v-model="form.couponName"></el-input>
<el-button @click="test">点击</el-button>
// data
blurIndex: null // 光标位置
// method
testBlur(e) {
this.blurIndex = e.srcElement.selectionStart
},
test(e) {
let index = this.blurIndex
let str = this.form.couponName
this.form.couponName = str.slice(0, index) + '{test}' + str.slice(index)
}