7

vue 元素样式修改

 4 years ago
source link: https://segmentfault.com/a/1190000040300692
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

vue 元素样式修改

发布于 21 分钟前

这里是使用错误。ref有两种情况:第一,如果在普通的 DOM 元素上使用,引用指向的就是 DOM 元素。第二,如果用在子组件上,引用就指向组件实例。你这种情况,就是第二种,应用在组件上,那么如果想要获取dom,需要使用this.$refs.wrap.$el来获取组建的跟容器dom节点,然后设置样式。当然如果你想设置slot里面的元素,那么在拿到 根容器dom节点后,就可以通过正常的querySelector等方法获取你想要的任何dom节点了如果还有问题,欢迎再次讨论。?

  // this.$nextTick(() => {
  //   let height = this.$refs.bgImg.offsetHeight;
  //   let width = this.$refs.bgImg.offsetWidth;
  //   this.$refs.bgImg.style.height = (height * this.num) / 100 + "px";
  //   this.$refs.bgImg.style.width = (width * this.num) / 100 + "px";
  // });

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK