Vue获取动态样式的宽度

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

  

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

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

你可能感兴趣的:(vue.js)