用vue 获取动态元素的宽度。首页,要放在this.$nextTick里面,其实要使用$el挂载此元素,下面贴代码

  <el-input auto-complete="off" v-model="company.companyName" ref="companyStyle"></el-input>

先定义一个ref=companyStyle,我们来获取此元素的宽度,

  newAddBtn(){
        let me = this;
        this.$nextTick(function () {
          me.inputStyWidth = me.$refs.companyStyle.$el.clientWidth + 'px';
        
        })
这样我们就获取到了这个元素的宽度了
Logo

前往低代码交流专区

更多推荐