直接上源码,
注意的坑
1、小程序的 watch 监听不能用,在H5 平台这样没问题,反正就是这玩意不好用。
2、父组件调用子组件的方法得放到mounted里,不然就是undefined
加载组件
{ { loading_title }}
{ { loading_title }}
/*
名称:简单全屏loading
日期:2020-02-25
作者:hj
目标:支持微信小程序、web、app
*/
export default {
name: "pre_loading_full",
data() {
return {
show_loading: false,
show_wx_loading: false,
t_height: 0,
t_width: 0,
loading_title: '玩命加载中'
};
},
// watch 不好用,换方法
// 小程序的 watch 监听不能用,在H5 平台这样没问题
// watch: {
// pre_show_loading(val) {
// console.log('监视 '+val);
// if(val=='false'){
// this.show_loading=false;
// }else{
// this.show_loading=true;
// }
// this.beginLoading();
// }
// },
methods: {
pre_loading: function(val) {
var type = '';
type = uni.getSystemInfoSync().platform;
console.log('开始加载。。。。。。。。。' + type);
if (type == 'android' || type == 'ios') {
console.log('运行' + type + '上');
this.show_loading = val?true:false;
this.beginLoading();
} else if (type == 'devtools') {
console.log('运行在开发者工具上');
console.log('可用宽度=' + uni.getSystemInfoSync().windowWidth);
this.show_loading = false;
this.show_wx_loading = val?true:false;
if(this.show_wx_loading){
this.t_height = uni.getSystemInfoSync().windowHeight;
this.t_width = uni.getSystemInfoSync().windowWidth;
}else{
this.t_height=0;
this.t_width=0;
}
this.beginLoading2();
} else {
console.log('运行' + type + '上');
this.show_loading = val?true:false;;
this.beginLoading();
}
},
beginLoading: function() {
var bl;
var num = 1;
var that = this;
bl = setInterval(function() {