At the moment, I am facing a challenge where I need to import a CSS file conditionally based on the user's browser. To keep the CSS file from being global, I have implemented the following code:
created() {
this.checkIsMobile()
},
methods: {
checkIsMobile(){
var isMobile = new MobileDetect(window.navigator.userAgent);
if (isMobile.mobile()){
$('head').append('<link rel="stylesheet" type="text/css" href="@/assets/css/main-pc.css">');
}else {
$('head').append('<link rel="stylesheet" type="text/css" href="@/assets/css/main-m.css">'); //must be load external css
}
},
However, this approach does not work as expected because it involves internal CSS.
I am unable to import within a style tag due to some links to other images in my CSS. Doing so leads to the error relative modules were not found
Is there a way to achieve this without having to upload the CSS file elsewhere?
Edit: For more insights into a similar issue (without using jQuery), you can refer to this question.