[关闭]
@Wangww0925 2019-08-07T05:46:31.000000Z 字数 1062 阅读 202

动态修改class

vue-cli


关键代码

  1. <template>
  2. <div>
  3. <div class="w check">
  4. <p :class="{'active':item.active}" v-for="item in checkList" @click="checkFun(item)">
  5. <i></i>{{item.name}}
  6. </p>
  7. </div>
  8. </div>
  9. </template>
  10. <script>
  11. export default {
  12. data () {
  13. return {
  14. checkList: [
  15. { name: 'Css'},
  16. { name: 'Css预处理器' },
  17. { name: 'HTML' },
  18. { name: 'JavaScript' },
  19. { name: '模板' },
  20. { name: '框架' },
  21. { name: 'Vue' },
  22. { name: '杂谈' },
  23. { name: '性能' },
  24. { name: '基础' },
  25. { name: '基础' },
  26. { name: '基础' },
  27. { name: '基础' },
  28. ]
  29. }
  30. },
  31. methods: {
  32. checkFun(that){
  33. that.active ? this.$set(that,'active',false) : this.$set(that,'active',true);
  34. }
  35. }
  36. }
  37. </script>
  38. <style scoped lang="stylus">
  39. p
  40. width:100%;
  41. line-height:30px;
  42. width:auto;
  43. display: inline-block;
  44. margin:0px 15px 0px 0px;
  45. cursor:pointer;
  46. i
  47. width:14px;
  48. height:14px;
  49. border:1px solid #ddd;
  50. margin-right:8px;
  51. vertical-align:-3px;
  52. border-radius:3px;
  53. p.active
  54. color:#81D841;
  55. i
  56. border-color: #81D841;
  57. background-color: #81D841;
  58. background-repeat: no-repeat;
  59. background-position: center center;
  60. background-size: contain;
  61. </style>

作者 wendy
2018 年 1月 9日


参考文献

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注