简体   繁体   English

使用 class 名称为一个特定的 Vuetify 范围组件设置样式

[英]Style one specific Vuetify scoped component using class names

I need to add some scoped style to this Vuetify v-text-field component.我需要向这个 Vuetify v-text-field组件添加一些范围样式。

<v-col cols="5">
  <v-row no-gutters class="flex-nowrap">
    <v-col>
      <v-text-field
        v-model="textFilter"
        data-test-id="search-field"
        placeholder="'Search by account name'"
      >
        <template slot="append" class="searchButtons">
          <v-btn
           type="submit"
           data-test-id="search"
           @click="updateFilter"
           >
             Search
           </v-btn>
        </template>
      </v-text-field>
    </v-col>
  </v-row>
</v-col>

So I inspected the element, I found the Vuetify class name and scoped the style I need like this:所以我检查了元素,我发现了 Vuetify class 名称并将我需要的样式定义为:

<style lang="scss" scoped>
  ::v-deep .v-text-field > .v-input__control > .v-input__slot {
    padding-left: 8px !important;
    padding-right: 0 !important;
  }
</style>

The problem is that I have a few other Vuetify components in the same scope that use the same class names, and of course they are also being affected by that style above.问题是我在同一个 scope 中有一些其他 Vuetify 组件,它们使用相同的 class 名称,当然它们也受到上述样式的影响。

I tried adding an additional class to my component (eg class="search-field" ), and to use it in the style selector (eg ::v-deep.search-field >.v-text-field >.v-input__control >.v-input__slot ), but it doesn't work (I guess it's because these classes are not exposed but generated by Vuetify).我尝试在我的组件中添加一个额外的 class(例如class="search-field" ),并在样式选择器中使用它(例如::v-deep.search-field >.v-text-field >.v-input__control >.v-input__slot ),但它不起作用(我猜这是因为这些类没有公开,而是由 Vuetify 生成)。

How can I select and style only that specific component?我怎样才能 select 和样式只特定组件?

Thanks谢谢

Solved in the end, by adding an id to the highest node and then selecting like this:最后解决了,给最高节点加一个id ,然后像这样选择:

TEMPLATE:模板:

<v-text-field
   id="search-field"
   v-model="textFilter"
   data-test-id="search-field"
   placeholder="'Search by account name'"
 > ...

STYLE tag:风格标签:

::v-deep #search-field > .v-text-field > .v-input__control > .v-input__slot {
  ...style
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM