Как изменить цвет заголовка таблицы в b-table BootstraVue

Я хочу изменить цвет b-таблицы в компоненте b-table BootstraVue. Вот простой пример:

<template>
    <div>
        <b-table :items="items" thead-class="greenColor">
        </b-table>
    </div>
</template>
<style scoped>
.greenColor, .table thead th, thead, th {
    background-color: #00FF00 !important;
}
</style>
<script>
export default {
    data() {
        return {
            items: [
                {name: "Paweł", surname: "Kowalski"},
                {name: "John", surname: "Nowak"}
            ]
        }
    }
}
</script>

Как видите, я попытался установить ad-класс (и набор классов правильно, но не работает) и изменить стиль элемента thead, но таблица все еще остается белой. У вас есть способ, которым я могу изменить цвет этого заголовка?

И некоторые из моих зависимостей от package.json: "nuxt": "^ 2.0.0", "bootstrap": "^ 4.1.3", "bootstrap-vue": "^ 2.0.0 "


person Krzysztof Karczewski    schedule 24.01.2020    source источник


Ответы (1)


Проблема, с которой вы столкнулись, заключается в том, что вы используете тег стиля scoped. Если вы хотите настроить таргетинг на подкомпоненты, вам необходимо использовать глубокий селектор, чтобы правильно настроить таргетинг на них.

new Vue({
  el: '#app',
  data() {
    return {
      items: [
        { first: 'Mikkel', last: 'Hansen', age: 16 }
      ],
      fields: [
        /* 
          Optionally define a class per header, 
          this will overlay whatever thead-class background you choose 
        */
        { key: 'first', thClass: 'bg-white text-dark' },
        { key: 'last' },
        { key: 'age' }
      ]
    }
  }
})
<script src="https://unpkg.com/[email protected]/dist/vue.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/bootstrap-vue.js"></script>

<link href="https://unpkg.com/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://unpkg.com/[email protected]/dist/bootstrap-vue.css" rel="stylesheet"/>

<div id="app">
  <!-- If the CSS class is globally available (like bg-dark) you can simply use it in thead-class -->
  <b-table :items="items" thead-class="green-bg bg-dark text-white"></b-table>
  
  <!-- Optinally you can use the fields property and define classes per column -->
  <b-table :items="items" :fields="fields" thead-class="green-bg bg-dark text-white"></b-table>
</div>

<!-- Disabled since it doesn't work for SO snippets.
<style scoped>
  /* Example of how to use a deep selector */
  /deep/ .green-bg {
    background-color: green;
  }
<style>
-->

person Hiws    schedule 24.01.2020