需求:

     slider侧边栏是宽度是动态的,使用jquery可以操作dom元素,设置宽高,但vue是避免操作dom

<template>
    <div class="slider">
        <h1>Hamy</h1>
    </div>
</template>
<script>
    export default{
        name:'index',
        data(){
            return{
                sliderStyle:{
                    width:'240px'
                }
            }
        }
    }
</script>

思路:

     通过给元素绑定style,在methods中通过改变this.sliderStyle.width来设置动态宽度

<template>
    <div class="slider" :style="sliderStyle">
        <h1>Hamy</h1>
    </div>
</template>

 

相关文章:

  • 2021-10-04
  • 2021-11-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-06
  • 2021-11-19
  • 2022-12-23
猜你喜欢
  • 2021-12-09
  • 2022-12-23
  • 2022-01-07
  • 2021-08-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案