想要實(shí)現(xiàn)的功能:點(diǎn)擊按鈕锥惋,在光標(biāo)停留的地方跪腹,插入一段文案:
<el-input @blur="testBlur" v-model="form.couponName"></el-input>
<el-button @click="test">點(diǎn)擊</el-button>
// data
blurIndex: null // 光標(biāo)位置
// 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)
}