Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

sass - Style one specific Vuetify scoped component using class names

I need to add some scoped style to this Vuetify v-text-field component.

<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:

<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.

I tried adding an additional class to my component (e.g. class="search-field"), and to use it in the style selector (e.g. ::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).

How can I select and style only that specific component?

Thanks

question from:https://stackoverflow.com/questions/65885388/style-one-specific-vuetify-scoped-component-using-class-names

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Solved in the end, by adding an id to the highest node and then selecting like this:

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
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...