简体   繁体   English

在组件端删除导入的CSS

[英]Removing imported CSS on component end

I have many components that import hosted css files as follows: 我有许多导入托管CSS文件的组件,如下所示:

<style scoped>
  @import 'https://test.com/path/to/my-stylesheets/styles.css';
</style>

What I am wanting is a way to remove these imported stylesheets on an end lifecycle hook such as beforeDestroy . 我想要的是一种在最终生命周期挂钩(例如beforeDestroy上删除这些导入的样式表的方法。

Is this possible? 这可能吗?

What you're trying to do depends on vue-loader (if you're using webpack) and it looks like a counter intuitive. 您要尝试执行的操作取决于vue-loader (如果使用的是webpack),并且看起来像是一种直观的计数器。 So, there's no reason for styles to be removed from document. 因此,没有理由从文档中删除样式。 What you can do is to define your CSS classes in stylesheets or as a data variable in viewmodel and assign/remove those classes during Vue component's lifecycle like beforeCreate/beforeDestroy etc. if you like. 您可以做的是在样式表中定义CSS类,或者在viewmodel中将其定义为数据变量,并在Vue组件的生命周期内分配/删除这些类,例如,如果愿意的话,例如beforeCreate / beforeDestroy等。

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

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