-
Notifications
You must be signed in to change notification settings - Fork 915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] Need for new option to manage css that is bound to a component. #580
Comments
From how I understand it, I don't think that this is a good solution. If I understand the problem that you want to solve correctly, you are worried that styles that some 3rd party plugin, e.g. a jQuery Plugin, uses, would conflict with other CSS rules. Is that correct? In that case, your solution makes that a bit more unlikely, but only insofar as the styles are gone when the component is not used. there will inevitably be cases where this component (which uses your above feature), and some other component, which has CSS rules that conflict the the ones of the plugin, will both be in the document at the same time. https://jsfiddle.net/Linusborg/2tvttm8a/ So this seems to add a false sense of security, and as soon as the above situation occurs, you will be wondering why sometimes the styles are ok, and sometimes they are not. I think a far better approach would be to tackle this hands on and include the styles always - the sooner you find you that something is clashing, the better. |
This is not an option for me because of the size of my project if the css of all plugins is included the page will become heavy. @kazupon made it clear that it is not possible to add scopeId to dynamic content, so the solution is to daclare them globally, another case is that I need to apply some styling to body like background-color e.t.c.. when a specific route/component is loaded. eg- main layout--normal body the way I see it there is no way to do this with scoped css. and if the styles are given globally then they stay and apply to the body even after the route/component is changed. that's why I think there should be a way to remove styles.
As this is going to a new option the consequences can be clearly documented and made clear to any one who decides to use this option |
In that case, just use webpack code splitting. Wrap the plugin's css and js in a module and lazy-load that in your component when you need it. Then the css will be loaded only when needed, but stay in the page (not a problem in my book)
That should be solved by adding/removing classes, not loading/ unloading css from a component. Css in vue files is meant for those components only. |
Currently doing that. that causes some problems. if css in page a overrides css in page b: if page b loads first everything is okay, But if page a loads first and then page b then page b is broken due to css override.
that staying on the page is my problem.
the way i want is the routing work like any normal html site, the css in that page is only for that page and no other styles to worry about, |
|
I think the original poster was not so much talking about styles from external libraries conflicting with other styles, but rather applying styles from within the .vue file to dynamically created DOM nodes within the template. See the following as an example case:
Please see the full gist. The intention here is that all paragraphs within this component have a font-size of 3em. This is true for the static paragraph within the template. The second paragraph (created from the The reason for this is as part of the css compilation the css selector There are two things that would complicate this solution. Firstly, the style for the root node still needs to be applied as Secondly, it's not clear how this would work with components composed in via slots. Do they inherit the styles (as they would if this was just straight html; this is what would happen with this implementation) or should they not be affected by styles in their parent component (might be harder to do with this approach). The workaround is not to use the |
For elements that are created dynamically by the dev with them DOM API instead of letting Vue handle this, I think the solution is pretty straightforward: get the Since these elements are handled outside of the dom that Vue controls, I don't think vue-loadet should have any responsibility in their styling. |
Fair enough I guess. The main drawback having to manually add the As I mentioned above, simply leaving out the The recommendation to manually add the Just as an example of how the manual
|
Closing outdated issues - this should be solvable with |
The vue-loader doesn't support the styling of dynamic content when used with scoped css.
#559
So I'm thinking that there should be another mode than scoped css to handle the css that can be applied to all the elements as long as the component is loaded.
if the styles are a part of the component then they will be applied only when the component is loaded.
This is extremely useful when using vue-router for changing views, so only the styles needed for the component are loaded and removed with the component.
example:
can be compiled to:
This way it will be very useful to projects using jquery plugins or others where most of the content is generated dynamically.
And as it a build step I don't think it will effect the final build product.
The text was updated successfully, but these errors were encountered: