vue pages PC-side and mobile terminal compatible program

A , achieved through the media in response to the query of formula (@media)
advantages : for small pages, less user interaction program, fewer code amount;
disadvantages : the page content is too large, excessive user interaction time, if by @media one to change, then it may make the amount of code a lot, and it is not easy to maintain. Therefore we need another way to solve this problem.

Two , is determined by the type of opening device, and the way to distinguish between the interface needs to be displayed

 //App.vue
  mounted() {
      if (this._isMobile()) {
        alert("手机端");
        // this.$router.replace('/m_index');
      } else {
        alert("pc端");
        // this.$router.replace('/pc_index');
      }
    },
    methods: {
      //App.vue
      _isMobile() {
        let flag = navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)
        return flag;
      }
  }

 

Guess you like

Origin www.cnblogs.com/liangtao999/p/12047734.html