这个transition为什么没有变化?

点击没有反应

<template>
  <div id="app">
      <button @click="show = !show">变变变</button>
      <div style="width: 100px;height: 100px;background-color: blue;" :class="{'active': show}"></div>
  </div>
</template>

<script>
export default {
  name: '',
  data: function(){
    return {
      show: true
    }
  }
}
</script>

<style scoped>
  .active{
    width:300px;
    transition: width 2s;
    -moz-transition: width 2s;
    -webkit-transition: width 2s;
    -o-transition: width 2s;
  }
</style>
阅读 1.6k
2 个回答

换成这样可以实现效果

<template>
  <div id="app">
    <button @click="show = !show">变变变</button>
    <div :class="[show ? 'active' : 'box']"></div>
  </div>
</template>

<script>
export default {
  name: "",
  data: function () {
    return {
      show: true,
    };
  },
};
</script>

<style scoped>
.active {
  width: 300px !important;
  height: 100px;
  transition: width 2s !important;
  -moz-transition: width 2s !important;
  -webkit-transition: width 2s !important;
  -o-transition: width 2s !important;
  background-color: blue;
}
.box {
  width: 100px;
  height: 100px;
  background-color: blue;
}
</style>

内联样式权重高于class,width没有变化

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题