Преглед изворни кода

解决系统返回键picker层的消失问题

wgl пре 4 година
родитељ
комит
19cb1b21f5
1 измењених фајлова са 28 додато и 1 уклоњено
  1. 28 1
      src/projects/business/App.vue

+ 28 - 1
src/projects/business/App.vue

@@ -12,7 +12,14 @@
 	export default {
 		name: 'Home',
 		created() {},
-		methods: {},
+		methods: {
+			removeElement(element) {
+				for (var i = 0; i < element.length; i++) {
+					console.log(element[i]);
+					document.body.removeChild(element[i]);
+				}
+			}
+		},
 		mounted() {
 			mui('body').on('tap', '.kfz', function() {
 				mui.toast('开发中');
@@ -21,6 +28,26 @@
 				document.location.href = this.href;
 			});
 		},
+		watch: {
+			//解决系统返回键app外的元素仍然存在的问题
+			'$route': function(to, from) {
+				var muidtpicker = document.getElementsByClassName('mui-dtpicker mui-active');
+				var muibackdrop = document.getElementsByClassName('mui-backdrop');
+				var muipoppicker = document.getElementsByClassName('mui-poppicker mui-active');
+				if (muidtpicker) {
+					this.removeElement(muidtpicker);
+					//console.log(muidtpicker)
+				}
+				if (muibackdrop) {
+					this.removeElement(muibackdrop);
+					//console.log(muibackdrop)
+				}
+				if (muipoppicker) {
+					this.removeElement(muipoppicker);
+					//console.log(muibackdrop)
+				}
+			}
+		},
 	}
 </script>