问题梳理:在uni-app中,使用input标签,编译后会自动转化为uni-input组件,导致focus伪元素不生效。
<template>
<view>
<input
type="text" class="input" placeholder="点击之后聚焦"
@focus="addFocus('myInput')" @blur="removeFocus('myInput')" ref="myInput"
>
</view>
</template>
<script>
export default {
methods: {
addFocus(rf){
this.$refs[rf].$el.classList.add("focus-input");
},
removeFocus(rf){
this.$refs[rf].$el.classList.remove("focus-input");
}
}
}
</script>
<style>
.input{
border: 1px red solid;
}
.focus-input{
border: 1px blue solid;
}
</style>