使用Vue里面的ref 控制DOM元素的样式marginleft,marginLeft的只是变化了,但是视图没有变化,求解答

使用Vue里面的ref 控制DOM元素的样式marginleft,marginLeft的只是变化了,但是视图没有变化,求解答

<template>
  <div>
    <div class="roll_header">
      <div class="flex_item" v-for="(ti,index) in pagetitle" :key="ti" @click="changeClassify($event,index)" :class="{'changeclassify':index==temps}">{{ti}}</div>
    </div>
    <div class="roll_bar">
      <div class="bar_item" ref="baritem"></div>
    </div>
  </div>
</template>

<script>
export default {
  data(){
    return{
      pagetitle:["登录","注册"],
      temps:0,
    }
  },
  methods:{
    changeClassify(event,index){
      // 改变temps的值,当前点击的控制的元素让他拥有changecolor样式
      this.temps=index;
      // 得到元素的宽度用来计算bar要移动多远
      let dis=event.target.offsetWidth;
      let distance=dis*index;
        // 注意拼接px
      this.$set(this.$refs.baritem.style,'marginleft',distance+'px')
      console.log(this.$refs.baritem.style)
    }
  }
};
</script>
<style>
.roll_header {
  width: 100%;
  height: 46px;
  display: flex;
  justify-content: center;
  line-height: 46px;
  color: rgb(121, 121, 121);
  font-size: 18px;
  cursor: pointer;
}
.flex_item {
  width: 60px;
  text-align: center;
  /* border: 1px solid rebeccapurple; */
}
.roll_bar{
  width: 180px;
  height:3px;
  border:1px solid rgb(223, 223, 223);
  background: white;
  margin: -4px auto;
  padding:0 30px;
  border-radius:2px;
}
.bar_item{
  width:60px;
  height:100%;
  background: coral;
  border-radius:4px;
}
.login{
  color: coral;
}
/* 选择拥有样式 */
.changeclassify{
  color: coral;
}

</style>

这是点击检测看赋值没问题,但是视图就是不变啊,头秃!!!!
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值