你可以在 v-alert 中通过以下方式更改 [vuetify.js] 图标颜色:

huangapple go评论43阅读模式
英文:

How can I change my [vuetify.js] icon color in v-alert

问题

Am having trouble trying to change the icon color in v-alert .

```html
<v-alert
        v-model="alert1"
        dismissible
        width="300px"
        style="
          position: fixed;
          left: 50%;
          bottom: 50px;
          transform: translate(-50%, -50%);
          margin: 0 auto;
          z-index: 1000001 !important;
          color: white;
        "
        icon="mdi-alert"
        color="orange"
      >
        {{ alertData1 }}
</v-alert>
英文:

Am having trouble trying to change the icon color in v-alert .

&lt;v-alert
        v-model=&quot;alert1&quot;
        dismissible
        width=&quot;300px&quot;
      
        style=&quot;
          position: fixed;
          left: 50%;
          bottom: 50px;
          transform: translate(-50%, -50%);
          margin: 0 auto;
          z-index: 1000001 !important;
          color:white;
        &quot;
        icon=&quot;mdi-alert&quot;
        color=&quot;orange&quot;
      &gt;
        {{ alertData1 }}
      &lt;/v-alert&gt;

答案1

得分: 0

你没有提到想要为警告图标设置哪种颜色。
但是,您可以简单地使用 dark 属性,而不是使用CSS,这将使文本和图标都变为白色。

演示-

<!-- 开始代码片段:js 隐藏:false 控制台:false babel:false -->

<!-- 语言:lang-js -->
new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  data() {
    return {
      alert1: true,
      alertData1: "My Alert"
    }
  }
})

<!-- 语言:lang-html -->
<script src="https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify@2.3.1/dist/vuetify.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vuetify@2.3.1/dist/vuetify.min.css">
<link href="https://cdn.jsdelivr.net/npm/@mdi/font@6.x/css/materialdesignicons.min.css" rel="stylesheet">

<div id="app">
  <v-app>
    <v-alert
        v-model="alert1"
        dismissible
        dark
        width="300px"
        style="
          position: fixed;
          left: 10%;
          top: 50px;
          margin: 0 auto;
          z-index: 1000001 !important;
        "
        icon="mdi-alert"
        color="orange"
      >
        {{ alertData1 }}
      </v-alert>
  </v-app>
</div>

<!-- 结束代码片段 -->

如果您只想为警告图标设置特定颜色,那么可以使用自定义CSS。例如-

.mdi-alert {
  color: red !important;
}

演示-

<!-- 开始代码片段:js 隐藏:false 控制台:false babel:false -->

<!-- 语言:lang-js -->
new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  data() {
    return {
      alert1: true,
      alertData1: "My Alert"
    }
  }
})

<!-- 语言:lang-css -->
.mdi-alert {
  color: red !important;
}

<!-- 语言:lang-html -->
<script src="https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify@2.3.1/dist/vuetify.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vuetify@2.3.1/dist/vuetify.min.css">
<link href="https://cdn.jsdelivr.net/npm/@mdi/font@6.x/css/materialdesignicons.min.css" rel="stylesheet">

<div id="app">
  <v-app>
    <v-alert
        v-model="alert1"
        dismissible
        dark
        width="300px"
        style="
          position: fixed;
          left: 10%;
          top: 50px;
          margin: 0 auto;
          z-index: 1000001 !important;
        "
        icon="mdi-alert"
        color="orange"
      >
        {{ alertData1 }}
      </v-alert>
  </v-app>
</div>

<!-- 结束代码片段 -->
英文:

You didn't mention which color you want to give to the alert icon.
However, instead of using CSS, you can simply use the dark prop which will make the text and icon both white.

Working demo-

<!-- begin snippet: js hide: false console: false babel: false -->

<!-- language: lang-js -->

new Vue({
  el: &#39;#app&#39;,
  vuetify: new Vuetify(),
  data() {
    return {
      alert1: true,
      alertData1: &quot;My Alert&quot;
    }
  }
})

<!-- language: lang-html -->

&lt;script src=&quot;https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://cdn.jsdelivr.net/npm/vuetify@2.3.1/dist/vuetify.min.js&quot;&gt;&lt;/script&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdn.jsdelivr.net/npm/vuetify@2.3.1/dist/vuetify.min.css&quot;/&gt;
&lt;link href=&quot;https://cdn.jsdelivr.net/npm/@mdi/font@6.x/css/materialdesignicons.min.css&quot; rel=&quot;stylesheet&quot;&gt;

&lt;div id=&quot;app&quot;&gt;
  &lt;v-app&gt;
    &lt;v-alert
        v-model=&quot;alert1&quot;
        dismissible
        dark
        width=&quot;300px&quot;
        style=&quot;
          position: fixed;
          left: 10%;
          top: 50px;
          margin: 0 auto;
          z-index: 1000001 !important;
        &quot;
        icon=&quot;mdi-alert&quot;
        color=&quot;orange&quot;
      &gt;
        {{ alertData1 }}
      &lt;/v-alert&gt;

  &lt;/v-app&gt;
&lt;/div&gt;

<!-- end snippet -->

And if you want to give a specific color to the warning icon only then you can use custom CSS. For example-

.mdi-alert {
  color: red !important;
}

Working demo-

<!-- begin snippet: js hide: false console: false babel: false -->

<!-- language: lang-js -->

new Vue({
  el: &#39;#app&#39;,
  vuetify: new Vuetify(),
  data() {
    return {
      alert1: true,
      alertData1: &quot;My Alert&quot;
    }
  }
})

<!-- language: lang-css -->

.mdi-alert {
  color: red !important;
}

<!-- language: lang-html -->

&lt;script src=&quot;https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://cdn.jsdelivr.net/npm/vuetify@2.3.1/dist/vuetify.min.js&quot;&gt;&lt;/script&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdn.jsdelivr.net/npm/vuetify@2.3.1/dist/vuetify.min.css&quot;/&gt;
&lt;link href=&quot;https://cdn.jsdelivr.net/npm/@mdi/font@6.x/css/materialdesignicons.min.css&quot; rel=&quot;stylesheet&quot;&gt;

&lt;div id=&quot;app&quot;&gt;
  &lt;v-app&gt;
    &lt;v-alert
        v-model=&quot;alert1&quot;
        dismissible
        dark
        width=&quot;300px&quot;
        style=&quot;
          position: fixed;
          left: 10%;
          top: 50px;
          margin: 0 auto;
          z-index: 1000001 !important;
        &quot;
        icon=&quot;mdi-alert&quot;
        color=&quot;orange&quot;
      &gt;
        {{ alertData1 }}
      &lt;/v-alert&gt;

  &lt;/v-app&gt;
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年3月15日 20:57:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/75745040.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定