Element UI el-input 定位元素的几种方法
使用 'el-input__inner' 这个参数好像定位不太准确,无法获取到元素,能不能用其它元素帮我定位内容?
如果使用 'el-input__inner' 不能准确地定位元素,可以尝试使用以下方式进行定位:
- 使用 'el-input' 的 ref 属性获取 'el-input' 组件的实例,然后通过实例中的 '$refs' 属性获取内部元素:
<template>
<el-input ref='myInput' v-model='inputValue'></el-input>
</template>
<script>
export default {
data() {
return {
inputValue: ''
}
},
mounted() {
const innerInput = this.$refs.myInput.$refs.input;
// 使用innerInput进行操作
}
}
</script>
- 直接使用原生的 'querySelector' 或 'getElementById' 方法获取内部元素:
<template>
<div>
<el-input id='myInput' v-model='inputValue'></el-input>
</div>
</template>
<script>
export default {
data() {
return {
inputValue: ''
}
},
mounted() {
const innerInput = document.querySelector('#myInput input');
// 使用innerInput进行操作
}
}
</script>
原文地址: https://www.cveoy.top/t/topic/lRuT 著作权归作者所有。请勿转载和采集!