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
367 views
in Technique[技术] by (71.8m points)

javascript - 有条件地添加不同的CSS文件(Add different css files conditionally)

I have a component and multiple style files as styles1.css, styles2.css, and styles3.css .

(我有一个组件和多个样式文件,如styles1.css, styles2.css,styles3.css 。)

I want to use them conditionally.

(我想有条件地使用它们。)

Like for user1 I want to load styles1.css for user2 it should load styles2.css and so on.

(像user1一样,我想为user2加载styles1.css ,它应该加载styles2.css ,依此类推。)

I tried loading i using require but no luck.

(我尝试使用require加载但没有运气。)

Your help will be highly appreciated.

(非常感谢您的帮助。)

  ask by Saurabh Agrawal translate from so

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

1 Reply

0 votes
by (71.8m points)

Did you try to create separate components and base class?

(您是否尝试创建单独的组件和基类?)

Because I think the logic of those components needs to be the same, just the styles should be different.

(因为我认为这些组件的逻辑必须相同,所以样式应该不同。)

So try to define one base TS class and defined new components that will be using that class and import new styles for each new component.

(因此,尝试定义一个基本TS类并定义将使用该类的新组件,并为每个新组件导入新样式。)

PS.

(PS。)

I do not use this kind of tricks, but maybe it will help.

(我不使用这种技巧,但也许会有所帮助。)


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

...