在vue中添加enter事件
js部分
在created生命周期中添加一个全局事件
created(){
let that = this
document.onkeydown = function (event) {
// console.log(event)
// console.log(event.target)
// console.log($(event.target).text())
// console.log(event.target)
let key = window.event.keyCode;
// console.log(key)
if (key === 13){
event.preventDefault()
var regText = new RegExp("^[0-9a-zA-Z-_\u4e00-\u9fa5]+$");
var text_str = $(event.target).text()
if(!regText.test(text_str)){
that.$message({
message: '设备名含有有特殊字符',
type: 'warning'
});
return false
} else{
that.edit_deviewName=text_str
}
// console.log("11111")
$(event.target).removeClass('choseEqlistStyle')
$(event.target).attr("contenteditable","false")
}
}
},