pwindy  
在完成任务的同时,还需要不断“复盘”,不论你多么的忙,都需要留下时间思考,可以思考哪些地方做的好,哪些地方我们可以改进,应该如何改进,注重总结才是王道

template 中需要动态定义样式,通常做法:

<template>
  <div :style="{ color: textColor }">Text</div>
</template>

<script>
export default {
  data() {
    return {
      textColor: '#ff5000'
    }
  }
}
</script>

 

 

高端做法:

1.定义 scss 文件

$menuActiveText:#409EFF;

:export {
  menuActiveText: $menuActiveText;
}

2.在 js 中引用:

  • 使用 import 引用 scss 文件
  • 定义 computed 将 styles 对象变成响应式对象
  • 在 template 中使用 styles 对象
<template>
  <div :style="{ color: styles.menuActiveText }">Text</div>
</template>

<script>
import styles from '@/styles/variables.scss'

export default {
  computed: {
    styles() {
      return styles
    }
  }
}
</script>

 

posted on 2021-11-12 11:06  pwindy  阅读(53)  评论(0)    收藏  举报