2

I have following simple component:

<template>
    <div>
        <b-form-group label="From:" label-align="left" label-for="nested-from">
            <date-pick :displayFormat="'DD/MM/YYYY'" v-model.trim="search_form.date_from"></date-pick>
          </b-form-group>
        </b-col>
    </div>
</template>

<script>
export default {
    name: 'simpleComp'
}
</script>

<style scoped lang="scss">
@import "~vue-date-pick/src/vueDatePick.scss";

.vdpComponent.vdpWithInput > input {
  @extend .form-control !optional;
  display: block;
  border: 5px solid blue !important;
  width: 100%;
  height: calc(1.5em + 0.75rem + 2px);
  padding: 0.375rem 0.75rem;
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.5;
  color: #495057;
  background-color: #fff;
  background-clip: padding-box;
  border: 1px solid #ced4da;
  border-radius: 0.25rem;
  -webkit-transition: border-color 0.15s ease-in-out, -webkit-box-shadow 0.15s ease-in-out;
  transition: border-color 0.15s ease-in-out, -webkit-box-shadow 0.15s ease-in-out;
  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out, -webkit-box-shadow 0.15s ease-in-out;
}
</style>

here is the screenshot on console:

enter image description here

This's just a sample of a big project, basically I have an input in my component and styles don't get applied to it, but if I remove scoped then everything is back on track, but I want to keep it in scoped level.

I searched a bit and find this answer from SO:

For some reason, scoped styles don't get applied during hot reload when they are first added to the component. Full page reload fixes the issue, from there the styles, since they have been detected, get updated with consecutive hot reloads.

This answer is not convincing, like for what reasons? and how do I avoid it and fix the problem? How do I do a full hot reload when the home page is loaded?

I tried refreshing the page? rerunning the dev server, but still didn't work? Can anyone help? Thanks in advance.

13
  • Have you tried using class or id selectors to apply styles? Commented Jan 21, 2021 at 9:30
  • yes, I tried everything so far Commented Jan 21, 2021 at 9:32
  • Try display: inline-block!important Commented Jan 21, 2021 at 9:37
  • I tried this ` border: 5px solid blue !important;` it doesn't work. but if I apply this style from console it works without important. Commented Jan 21, 2021 at 9:40
  • 2
    Please provide the full code so we can see. The code you have supplied as an example does not suffer from any scoping or child component deep selector issues. Commented Jan 21, 2021 at 9:58

1 Answer 1

5

As told in the previous comments, since you're using SCSS here and targeting a 3rd party component, you need to write it this way

::v-deep .vdpWithInput input {
  // your fancy style here
}

It will help having it scoped in this specific component and not bleeding all over your app.

Useful link for the deep selectors: https://vue-loader.vuejs.org/guide/scoped-css.html#deep-selectors

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.