我现在在做一个与用户聊天的界面,通过点击<router-link tag="li">的路由时,聊天框 <div class="content" contenteditable="true" v-focus="focusflag"> </div>获取焦点。
相关代码为:
export default {
name: 'info-chat',
data() {
return {
focusflag:false,
staticImgPath:gbs.staticImgPath,
}
},
watch:{
$route(to,from){
alert(to);
this.focusflag = true;
}
},
directives: {
focus: {
insert: function (el, {value}) {
alert(value);
if (value) {
el.focus();
}
}
}
},
}
但是当我点击li时,页面并没有执行directives中的focus方法,请问如何解决呢?