如何从替代中选择一种颜色作为默认值?

如何解决如何从替代中选择一种颜色作为默认值?

我已经为nuxt-tailwind项目创建了配色方案,但是我在这里遇到了问题。我需要使用这样的不透明度值来调用类名称:text-blue-500bg-blue-500一直。否则,将不会使用该样式。

当我不指定500不透明度时,如何使其自动选择?更清楚地说,我只想在不需要透明度的情况下指定以下内容:text-bluebg-blue

我找到了this question,但由于我没有为该类使用任何自定义名称,因此我认为它与我的情况不符。

请先查看我的顺风配置和我的组件之一,谢谢! tailwind.config.js

/*
 ** TailwindCSS Configuration File
 **
 ** Docs: https://tailwindcss.com/docs/configuration
 ** Default: https://github.com/tailwindcss/tailwindcss/blob/master/stubs/defaultConfig.stub.js
 */
module.exports = {
  important: true,theme: {
    // compatible with @nuxtjs/color-mode
    darkSelector: '.dark-mode',extend: {
      colors: {
        // all colors were generated from here: https://hihayk.github.io/scale
        white: 'white',black: '#2C3E50',blue: {
          900: '#052B80',800: '#09369F',700: '#0E43BF',600: '#134FDF',500: '#1A5CFF',400: '#438BFF',300: '#6FB4FF',200: '#9DD5FF',100: '#CDEFFF',},green: {
          900: '#30420A',800: '#315C0F',700: '#287514',600: '#1A8D1D',500: '#21A543',400: '#38B34B',300: '#50C156',200: '#6FCD69',100: '#91D883',orange: {
          900: '#ADA500',800: '#C2B300',700: '#D6C000',600: '#EBCB00',500: '#FFD500',400: '#FFDD32',300: '#FFE464',200: '#FFEB95',100: '#FFF3C7',red: {
          900: '#AD002A',800: '#C20031',700: '#D6003A',600: '#E50043',500: '#EF064D',400: '#FC3273',300: '#FF6498',200: '#FF95BC',100: '#FFC7DD',teal: {
          900: '#007699',800: '#0081A5',700: '#008AB0',600: '#0193B9',500: '#099BC1',400: '#32B9D5',300: '#64D2E5',200: '#95E7F1',100: '#C7F6FA',grey: {
          900: '#515F6A',800: '#5C6A76',700: '#667581',600: '#71808C',500: '#7C8B97',400: '#94A3AC',300: '#ADBAC1',200: '#C7D1D6',100: '#E1E7E9',variants: {
    backgroundColor: [
      'dark','dark-hover','dark-group-hover','dark-even','dark-odd',],borderColor: ['dark','dark-focus','dark-focus-within'],textColor: ['dark','dark-active'],plugins: [require('tailwindcss-dark-mode')()],purge: {
    // Learn more on https://tailwindcss.com/docs/controlling-file-size/#removing-unused-css
    enabled: process.env.NODE_ENV === 'production',content: [
      'components/**/*.vue','layouts/**/*.vue','pages/**/*.vue','plugins/**/*.js','nuxt.config.js',tailwindcss: {
    // add '~tailwind.config` alias
    exposeConfig: true,}

CircularProgressIndicator.vue

<template>
  <progress class="cpi" :class="[colorClass]" />
</template>

<script lang="ts">
import { Vue,Component,Prop } from 'nuxt-property-decorator'

@Component({ name: 'CircularProgressIndicator' })
export default class CircularProgressIndicator extends Vue {
  @Prop({ type: String,default: null }) public color!: string
  @Prop({ type: String,default: null }) public size!: string

  get colorClass(): string | void {
    // if (this.color) return `text-${this.color}-500` // if i specify it like this,the colors applied
    if (this.color) return `text-${this.color}` // but not this one
  }
}
</script>

<style scoped>
.cpi {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  box-sizing: border-box;
  border: none;
  border-radius: 50%;
  padding: 0.25em;
  width: 3em;
  height: 3em;
  background-color: transparent;
  overflow: hidden;
  @apply text-base;
  @apply text-blue-500;
}

.cpi::-webkit-progress-bar {
  background-color: transparent;
}

/* Indeterminate */
.cpi:indeterminate {
  -webkit-mask-image: linear-gradient(transparent 50%,black 50%),linear-gradient(to right,transparent 50%,black 50%);
  mask-image: linear-gradient(transparent 50%,black 50%);
  animation: cpi 6s infinite cubic-bezier(0.3,0.6,1,1);
}

.cpi:indeterminate::before,.cpi:indeterminate::-webkit-progress-value {
  content: '';
  display: block;
  box-sizing: border-box;
  margin-bottom: 0.25em;
  border: solid 0.25em transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  width: 100% !important;
  height: 100%;
  background-color: transparent;
  animation: cpi-pseudo 0.75s infinite linear alternate;
}

.cpi:indeterminate::-moz-progress-bar {
  box-sizing: border-box;
  border: solid 0.25em transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  width: 100%;
  height: 100%;
  background-color: transparent;
  animation: cpi-pseudo 0.75s infinite linear alternate;
}

.cpi:indeterminate::-ms-fill {
  animation-name: -ms-ring;
}

@keyframes cpi {
  0% {
    transform: rotate(0deg);
  }
  12.5% {
    transform: rotate(180deg);
    animation-timing-function: linear;
  }
  25% {
    transform: rotate(630deg);
  }
  37.5% {
    transform: rotate(810deg);
    animation-timing-function: linear;
  }
  50% {
    transform: rotate(1260deg);
  }
  62.5% {
    transform: rotate(1440deg);
    animation-timing-function: linear;
  }
  75% {
    transform: rotate(1890deg);
  }
  87.5% {
    transform: rotate(2070deg);
    animation-timing-function: linear;
  }
  100% {
    transform: rotate(2520deg);
  }
}

@keyframes cpi-pseudo {
  0% {
    transform: rotate(-30deg);
  }
  29.4% {
    border-left-color: transparent;
  }
  29.41% {
    border-left-color: currentColor;
  }
  64.7% {
    border-bottom-color: transparent;
  }
  64.71% {
    border-bottom-color: currentColor;
  }
  100% {
    border-left-color: currentColor;
    border-bottom-color: currentColor;
    transform: rotate(225deg);
  }
}
</style>

index.vue

<template>
  <CircularProgressIndicator />
  <CircularProgressIndicator color="green" />
  <CircularProgressIndicator color="red" />
  <CircularProgressIndicator color="teal" />
  <CircularProgressIndicator color="grey" />
</template>

解决方法

似乎您已经接近...应该可以将if(this.color)函数扩展到完整的tst ...但是当前if(this.color)仅在返回true或false的情况下存在颜色...您真的不需要比较哪种颜色?

if(this.color =='blue'|| this.color =='green'){ 返回xyz }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-