2.在index.html中添加link标签,初始化一个主题文件
3.在Vue组件中进行动态切换
App.vue:
demo.vue(css):
demo.vue(html):
demo.vue(js):
效果:
[图片上传失败...(image-c7afd3-1640662035396)]
Public/css/theme_1.css:
[图片上传失败...(image-e00dc1-1640661903141)]
App.vue:
demo.vue(html):
demo.vue(js):
效果:
[图片上传失败...(image-ed39bb-1640662035396)]
src/assets/css/theme.less:
[图片上传失败...(image-b46701-1640662035396)]
main.js:
App.vue:
demo.vue(html):
demo.vue(js):
效果:
[图片上传失败...(image-f6b84f-1640662035396)]
目测你是vue+webpack开发。你应该使用extract-text-webpack-plugin这个插件来把你的vue里的css提取出来成单独文件。
new ExtractTextPlugin('css/[name].[contenthash:8].css')
但如果你使用vue-cli这应该是已经配置好了的,你可能是在开发模式中,所以没有提取出来,如果打包后可能就会提取出来。
此外,你如果要按需加载,你也要先做到组件按需加载,
如果是在webpack里就是这么写
router.map({
'/async': {
component: function (resolve) {
require(['./MyComponent.vue'], resolve)
}
}
})
详见:http://router.vuejs.org/zh-cn...
同时,你的ExtractTextPlugin
new ExtractTextPlugin('css/[name].[contenthash:8].css', {
allChuck: true
})