1.vue同个css文件

<div :class="isMobile ? 'backgroudImgMobile' : 'backgroudImgPc'">
  data() {
    return {
      isMobile: false
    };
  },
  mounted() {
    this.getScreen();
  },

  methods: {
    getScreen() {
      if (
        navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)
      ) {
        this.isMobile = true;
        console.log("手机");
      } else {
        this.isMobile = false;
        console.log("pc");
      }
    }
  }

第二种:加载不同的css文件,在getScreen方法写入该句

 document.write('<link href="css/phone.css" rel="stylesheet" type="text/css" media="screen" />');

 

相关文章:

  • 2022-12-23
  • 2021-12-18
  • 2022-02-08
  • 2022-12-23
  • 2021-11-26
  • 2021-06-27
  • 2022-12-23
  • 2021-12-10
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-11
  • 2021-12-29
  • 2021-11-26
  • 2022-02-05
  • 2021-12-10
相关资源
相似解决方案