设置loading & 移动端适配(rem)

2019-05-12  本文已影响0人  Grayly吖

一、设置\color{red}{loading}加载的几种方式

1、直接在组件中导入使用

     <script>
         import { Toast } from 'vant';
     </script>
      Toast.loading({
        mask: true,
        message: '加载中...'
      });

2、在main.js文件中引入,会自动在 Vue 的 prototype 上挂载 $toast 方法,在组件内通过this调用。

    //导入vants ui
    import Vant from 'vant';
    import 'vant/lib/index.css';
    Vue.use(Vant);
    import { Toast } from 'vant';
    import 'vant/lib/index.css';
    Vue.use( Toast );
    this.$toast('提示文案');

3、将Toast封装后便于使用

(1)新建文件夹untils,然后在untils文件夹下新建index.js文件
(2)在index.js文件中导入Toast模块,并使用

    import Vue from 'vue'
    //导入有赞轻提示
    import { Toast } from 'vant';
    import 'vant/lib/index.css';
    Vue.use(Toast);

(3)导出

    export const loading = () => {
        Toast.loading({
            // mask: true, //蒙层
            duration: 0,       // 持续展示 toast
            forbidClick: true, // 禁用背景点击
            loadingType: 'spinner',
            message: '加载中...'
        });
    }

(4)在main.js中通过解构导入,并在Vue的原型上添加属性,在组件内通过this调用

    //导入封装后的轻提示
    import { loading, clear } from './untils/index'
    Vue.prototype.$loading = loading
      //获取数据前加载loading
      this.$loading();

二、移动端适配方案

1、了解响应式布局

(1)通过媒体查询:\color{red}{@media}
      媒体查询可以让我们根据设备显示器的特性(如视口宽度、屏幕比例、设备方向:横向或纵向)为其设定CSS样式。(即根据设备的不同宽度为同一页面设置不同的css样式)

(2)写两套代码,一套PC端,一套移动端,通过\color{red}{userAgent}判断用户使用的设备,跳转到相应的网站

2、移动端的适配(rem)

3、在项目中配置\color{red}{rem}

     npm i  amfe-flexible --save
     import 'amfe-flexible';
     npm i   postcss-pxtorem --save
      const autoprefixer = require('autoprefixer');
      const pxtorem = require('postcss-pxtorem');
      
      module.exports = {
        css: {
          loaderOptions: {
            postcss: {
              plugins: [
                autoprefixer(),
                pxtorem({
                  rootValue: 37.5,
                  propList: ['*'],
                  // 该项仅在使用 Circle 组件时需要
                  // 原因参见 https://github.com/youzan/vant/issues/1948
                  selectorBlackList: ['van-circle__layer']
                })
              ]
            }
          }
        }
      };
上一篇 下一篇

猜你喜欢

热点阅读