TypeError:me.el. is undefined

本文介绍了当使用默认的destroy操作关闭Window后导致无法重新打开的问题,并提供了解决方案,包括设置windowCloseAction为'hide'以及优化DOM操作的方法。

今天遇到的错误

 

原因:由于点击window上的关闭按钮,默认动作是destroy(remove from DOM),所以window对象已经销毁了,所以再次点击时则找不到对象。

 

解决办法:

1.设置window closeAction:'hide'

2.减少对DOM的操作:

click:function(){
			if(typeof(resourceAddWin) != "undefined"){
				resourceAddWin.show();
				console.log("exist");
			}else{
				resourceAddWin = Ext.create('Fmis.view.ResourceAddWin',{}).show();
				console.log("new");
			}
			
				}

 

ps:感谢群里朋友提醒

:8081/#/stu:1 Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.Understand this errorAI :8081/#/stu:1 Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.Understand this errorAI :8081/#/stu:1 Uncaught (in promise) Error: Could not establish connection. Receiving end does not exist.Understand this errorAI content.js-c1c147bd.js:1 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'exception') at content.js-c1c147bd.js:1:42224 (anonymous) @ content.js-c1c147bd.js:1Understand this errorAI main.js:26 [Vue warn]: Property or method "handleOpen" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://v2.vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties. found in ---> <IndexCom> at src/components/index.vue <App> at src/App.vue <Root> warn @ vue.runtime.esm.js:4482 warnNonPresent_1 @ vue.runtime.esm.js:5082 get @ vue.runtime.esm.js:5115 render @ index.js??clonedRuleSet-40.use[0]!./node_modules/@vue/vue-loader-v15/lib/loaders/templateLoader.js??ruleSet[1].rules[3]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/components/index.vue?vue&type=template&id=47323bf2&scoped=true:44 Vue._render @ vue.runtime.esm.js:2649 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 init @ vue.runtime.esm.js:4277 merged @ vue.runtime.esm.js:4439 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 createChildren @ vue.runtime.esm.js:6335 createElm @ vue.runtime.esm.js:6243 patch @ vue.runtime.esm.js:6706 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 init @ vue.runtime.esm.js:4277 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 patch @ vue.runtime.esm.js:6737 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 eval @ main.js:26 ./src/main.js @ app.js:597 __webpack_require__ @ app.js:646 (anonymous) @ app.js:1797 __webpack_require__.O @ app.js:696 (anonymous) @ app.js:1798 (anonymous) @ app.js:1800Understand this errorAI main.js:26 [Vue warn]: Property or method "handleClose" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://v2.vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties. found in ---> <IndexCom> at src/components/index.vue <App> at src/App.vue <Root> warn @ vue.runtime.esm.js:4482 warnNonPresent_1 @ vue.runtime.esm.js:5082 get @ vue.runtime.esm.js:5115 render @ index.js??clonedRuleSet-40.use[0]!./node_modules/@vue/vue-loader-v15/lib/loaders/templateLoader.js??ruleSet[1].rules[3]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/components/index.vue?vue&type=template&id=47323bf2&scoped=true:45 Vue._render @ vue.runtime.esm.js:2649 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 init @ vue.runtime.esm.js:4277 merged @ vue.runtime.esm.js:4439 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 createChildren @ vue.runtime.esm.js:6335 createElm @ vue.runtime.esm.js:6243 patch @ vue.runtime.esm.js:6706 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 init @ vue.runtime.esm.js:4277 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 patch @ vue.runtime.esm.js:6737 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 eval @ main.js:26 ./src/main.js @ app.js:597 __webpack_require__ @ app.js:646 (anonymous) @ app.js:1797 __webpack_require__.O @ app.js:696 (anonymous) @ app.js:1798 (anonymous) @ app.js:1800Understand this errorAI main.js:26 [Vue warn]: Invalid handler for event "open": got undefined found in ---> <ElMenu> at packages/menu/src/menu.vue <ElAside> at packages/aside/src/main.vue <ElContainer> at packages/container/src/main.vue... (1 recursive calls) <IndexCom> at src/components/index.vue <App> at src/App.vue <Root> warn @ vue.runtime.esm.js:4482 updateListeners @ vue.runtime.esm.js:1859 updateComponentListeners @ vue.runtime.esm.js:3541 initEvents @ vue.runtime.esm.js:3520 Vue._init @ vue.runtime.esm.js:5443 VueComponent @ vue.runtime.esm.js:5576 createComponentInstanceForVnode @ vue.runtime.esm.js:4422 init @ vue.runtime.esm.js:4276 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 createChildren @ vue.runtime.esm.js:6335 createElm @ vue.runtime.esm.js:6243 patch @ vue.runtime.esm.js:6706 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 init @ vue.runtime.esm.js:4277 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 createChildren @ vue.runtime.esm.js:6335 createElm @ vue.runtime.esm.js:6243 patch @ vue.runtime.esm.js:6706 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 init @ vue.runtime.esm.js:4277 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 createChildren @ vue.runtime.esm.js:6335 createElm @ vue.runtime.esm.js:6243 patch @ vue.runtime.esm.js:6706 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 init @ vue.runtime.esm.js:4277 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 patch @ vue.runtime.esm.js:6706 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 init @ vue.runtime.esm.js:4277 merged @ vue.runtime.esm.js:4439 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 createChildren @ vue.runtime.esm.js:6335 createElm @ vue.runtime.esm.js:6243 patch @ vue.runtime.esm.js:6706 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 init @ vue.runtime.esm.js:4277 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 patch @ vue.runtime.esm.js:6737 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 eval @ main.js:26 ./src/main.js @ app.js:597 __webpack_require__ @ app.js:646 (anonymous) @ app.js:1797 __webpack_require__.O @ app.js:696 (anonymous) @ app.js:1798 (anonymous) @ app.js:1800Understand this errorAI main.js:26 [Vue warn]: Invalid handler for event "close": got undefined found in ---> <ElMenu> at packages/menu/src/menu.vue <ElAside> at packages/aside/src/main.vue <ElContainer> at packages/container/src/main.vue... (1 recursive calls) <IndexCom> at src/components/index.vue <App> at src/App.vue <Root> warn @ vue.runtime.esm.js:4482 updateListeners @ vue.runtime.esm.js:1859 updateComponentListeners @ vue.runtime.esm.js:3541 initEvents @ vue.runtime.esm.js:3520 Vue._init @ vue.runtime.esm.js:5443 VueComponent @ vue.runtime.esm.js:5576 createComponentInstanceForVnode @ vue.runtime.esm.js:4422 init @ vue.runtime.esm.js:4276 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 createChildren @ vue.runtime.esm.js:6335 createElm @ vue.runtime.esm.js:6243 patch @ vue.runtime.esm.js:6706 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 init @ vue.runtime.esm.js:4277 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 createChildren @ vue.runtime.esm.js:6335 createElm @ vue.runtime.esm.js:6243 patch @ vue.runtime.esm.js:6706 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 init @ vue.runtime.esm.js:4277 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 createChildren @ vue.runtime.esm.js:6335 createElm @ vue.runtime.esm.js:6243 patch @ vue.runtime.esm.js:6706 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 init @ vue.runtime.esm.js:4277 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 patch @ vue.runtime.esm.js:6706 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 init @ vue.runtime.esm.js:4277 merged @ vue.runtime.esm.js:4439 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 createChildren @ vue.runtime.esm.js:6335 createElm @ vue.runtime.esm.js:6243 patch @ vue.runtime.esm.js:6706 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 init @ vue.runtime.esm.js:4277 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 patch @ vue.runtime.esm.js:6737 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 eval @ main.js:26 ./src/main.js @ app.js:597 __webpack_require__ @ app.js:646 (anonymous) @ app.js:1797 __webpack_require__.O @ app.js:696 (anonymous) @ app.js:1798 (anonymous) @ app.js:1800Understand this errorAI main.js:26 [Vue warn]: Error in created hook: "TypeError: this.stuList is not a function" found in ---> <StudentList> at src/components/studentList.vue <ElMain> at packages/main/src/main.vue <ElContainer> at packages/container/src/main.vue... (1 recursive calls) <IndexCom> at src/components/index.vue <App> at src/App.vue <Root> warn @ vue.runtime.esm.js:4482 logError @ vue.runtime.esm.js:2985 globalHandleError @ vue.runtime.esm.js:2981 handleError @ vue.runtime.esm.js:2949 invokeWithErrorHandling @ vue.runtime.esm.js:2965 callHook$1 @ vue.runtime.esm.js:3929 Vue._init @ vue.runtime.esm.js:5449 VueComponent @ vue.runtime.esm.js:5576 createComponentInstanceForVnode @ vue.runtime.esm.js:4422 init @ vue.runtime.esm.js:4276 merged @ vue.runtime.esm.js:4439 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 createChildren @ vue.runtime.esm.js:6335 createElm @ vue.runtime.esm.js:6243 patch @ vue.runtime.esm.js:6706 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 init @ vue.runtime.esm.js:4277 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 createChildren @ vue.runtime.esm.js:6335 createElm @ vue.runtime.esm.js:6243 patch @ vue.runtime.esm.js:6706 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 init @ vue.runtime.esm.js:4277 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 createChildren @ vue.runtime.esm.js:6335 createElm @ vue.runtime.esm.js:6243 patch @ vue.runtime.esm.js:6706 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 init @ vue.runtime.esm.js:4277 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 patch @ vue.runtime.esm.js:6706 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 init @ vue.runtime.esm.js:4277 merged @ vue.runtime.esm.js:4439 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 createChildren @ vue.runtime.esm.js:6335 createElm @ vue.runtime.esm.js:6243 patch @ vue.runtime.esm.js:6706 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 init @ vue.runtime.esm.js:4277 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 patch @ vue.runtime.esm.js:6737 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 eval @ main.js:26 ./src/main.js @ app.js:597 __webpack_require__ @ app.js:646 (anonymous) @ app.js:1797 __webpack_require__.O @ app.js:696 (anonymous) @ app.js:1798 (anonymous) @ app.js:1800Understand this errorAI main.js:26 TypeError: this.stuList is not a function at VueComponent.created (index.js??clonedRuleSet-40.use[0]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/components/studentList.vue?vue&type=script&lang=js:6:10) at invokeWithErrorHandling (vue.runtime.esm.js:2957:57) at callHook$1 (vue.runtime.esm.js:3929:7) at Vue._init (vue.runtime.esm.js:5449:5) at new VueComponent (vue.runtime.esm.js:5576:12) at createComponentInstanceForVnode (vue.runtime.esm.js:4422:10) at init (vue.runtime.esm.js:4276:45) at merged (vue.runtime.esm.js:4439:5) at createComponent (vue.runtime.esm.js:6264:9) at createElm (vue.runtime.esm.js:6226:9) logError @ vue.runtime.esm.js:2989 globalHandleError @ vue.runtime.esm.js:2981 handleError @ vue.runtime.esm.js:2949 invokeWithErrorHandling @ vue.runtime.esm.js:2965 callHook$1 @ vue.runtime.esm.js:3929 Vue._init @ vue.runtime.esm.js:5449 VueComponent @ vue.runtime.esm.js:5576 createComponentInstanceForVnode @ vue.runtime.esm.js:4422 init @ vue.runtime.esm.js:4276 merged @ vue.runtime.esm.js:4439 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 createChildren @ vue.runtime.esm.js:6335 createElm @ vue.runtime.esm.js:6243 patch @ vue.runtime.esm.js:6706 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 init @ vue.runtime.esm.js:4277 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 createChildren @ vue.runtime.esm.js:6335 createElm @ vue.runtime.esm.js:6243 patch @ vue.runtime.esm.js:6706 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 init @ vue.runtime.esm.js:4277 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 createChildren @ vue.runtime.esm.js:6335 createElm @ vue.runtime.esm.js:6243 patch @ vue.runtime.esm.js:6706 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 init @ vue.runtime.esm.js:4277 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 patch @ vue.runtime.esm.js:6706 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 init @ vue.runtime.esm.js:4277 merged @ vue.runtime.esm.js:4439 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 createChildren @ vue.runtime.esm.js:6335 createElm @ vue.runtime.esm.js:6243 patch @ vue.runtime.esm.js:6706 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 init @ vue.runtime.esm.js:4277 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 patch @ vue.runtime.esm.js:6737 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 eval @ main.js:26 ./src/main.js @ app.js:597 __webpack_require__ @ app.js:646 (anonymous) @ app.js:1797 __webpack_require__.O @ app.js:696 (anonymous) @ app.js:1798 (anonymous) @ app.js:1800Understand this errorAI main.js:26 [Violation] Added non-passive event listener to a scroll-blocking 'mousewheel' event. Consider marking event handler as 'passive' to make the page more responsive. See https://www.chromestatus.com/feature/5745543795965952 mousewheel @ element-ui.common.js:1140 bind @ element-ui.common.js:1140 callHook @ vue.runtime.esm.js:6892 _update @ vue.runtime.esm.js:6812 updateDirectives @ vue.runtime.esm.js:6796 invokeCreateHooks @ vue.runtime.esm.js:6349 createElm @ vue.runtime.esm.js:6245 createChildren @ vue.runtime.esm.js:6335 createElm @ vue.runtime.esm.js:6243 patch @ vue.runtime.esm.js:6706 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 init @ vue.runtime.esm.js:4277 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 patch @ vue.runtime.esm.js:6706 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 init @ vue.runtime.esm.js:4277 merged @ vue.runtime.esm.js:4439 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 createChildren @ vue.runtime.esm.js:6335 createElm @ vue.runtime.esm.js:6243 patch @ vue.runtime.esm.js:6706 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 init @ vue.runtime.esm.js:4277 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 createChildren @ vue.runtime.esm.js:6335 createElm @ vue.runtime.esm.js:6243 patch @ vue.runtime.esm.js:6706 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 init @ vue.runtime.esm.js:4277 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 createChildren @ vue.runtime.esm.js:6335 createElm @ vue.runtime.esm.js:6243 patch @ vue.runtime.esm.js:6706 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 init @ vue.runtime.esm.js:4277 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 patch @ vue.runtime.esm.js:6706 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 init @ vue.runtime.esm.js:4277 merged @ vue.runtime.esm.js:4439 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 createChildren @ vue.runtime.esm.js:6335 createElm @ vue.runtime.esm.js:6243 patch @ vue.runtime.esm.js:6706 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 init @ vue.runtime.esm.js:4277 createComponent @ vue.runtime.esm.js:6264 createElm @ vue.runtime.esm.js:6226 patch @ vue.runtime.esm.js:6737 Vue._update @ vue.runtime.esm.js:3669 updateComponent @ vue.runtime.esm.js:3769 Watcher.get @ vue.runtime.esm.js:3363 Watcher @ vue.runtime.esm.js:3353 mountComponent @ vue.runtime.esm.js:3790 Vue.$mount @ vue.runtime.esm.js:8323 eval @ main.js:26 ./src/main.js @ app.js:597 __webpack_require__ @ app.js:646 (anonymous) @ app.js:1797 __webpack_require__.O @ app.js:696 (anonymous) @ app.js:1798 (anonymous) @ app.js:1800 main.js:26 [Intervention] Slow network is detected. See https://www.chromestatus.com/feature/5636954674692096 for more details. Fallback font will be used while loading: http://localhost:8081/fonts/element-icons.ff18efd1.woff vue.runtime.esm.js:8334 Download the Vue Devtools extension for a better development experience: https://github.com/vuejs/vue-devtools
最新发布
10-07
<template> <div> <baidu-map id="allmap" :center="center" :zoom="zoom" @ready="handler" style="height:9.45rem;width: 100%;" @click="getClickInfo" :scroll-wheel-zoom='true'> <div class="drawing-panel" style="z-index: 99;"> <button class = "btn" @click='play(1)' size="small">播放</button> <button class = "btn" @click='play(2)' size="small">暂停</button> <button class = "btn" @click='play(3)' size="small">停止</button> </div> </baidu-map> </div> </template> <script> export default { name: 'BtAddrBaiDu', data () { return { center: {lng: 114.085947, lat: 22.547}, zoom: 15, // 地图缩放比例,越大越细 point:"", gpsArr:[ { lng:114.000069, lat:22.500069 }, ],//后台拿到的gps点数组 speed:500,//速度 lushu:{},//路书 batteryId:"电池编号:"+this.$parent.$children[0].hwid, myMap: {} //地图 } }, mounted(){ this.handler() // 函数调用 }, methods: { handler({BMap, map}){ this.$nextTick(()=>{ this.$http({ url: this.$http.adornUrl('/mqtt/mtgpslocationinfo/queryGpsLocationInfos'), method: 'get', params: this.$http.adornParams({ 'limit': 50, 'thingid': this.$parent.$children[0].hwid //从父类的一个子类中获取hwid,子类中的hwid都是一样的 this.detailsparentmsg }) }).then(({data}) => { //无论有无数,都要画出地图 map.enableScrollWheelZoom(new BMap.Point(114.085947, 22.547), 15); map.centerAndZoom(); var arrPois = []; if (data && data.code === 0) { const socitem = data.data if (socitem && socitem.length > 0) { let clng = socitem[socitem.length-1].longitude; let clat = socitem[socitem.length-1].latitude; this.center = {lng: clng, lat: clat}; var myIcon = new BMap.Icon( require("../../../assets/img/markers.png"), new BMap.Size(23, 25), { offset: new BMap.Size(10, 25), // 指定定位位置 imageOffset: new BMap.Size(0, 0 - 11 * 25) // 设置图片偏移 }); for (let i = 0; i < socitem.length; i++) { var p0 = socitem[i].longitude; var p1 = socitem[i].latitude; var point = new BMap.Point(p0, p1); arrPois.push(point); //距离差距 var distance = this.getDistance(clat,clng, p1,p0); var content = "<table style='color: #FFF;'>"; content = content + "<tr><td> 电池编号:"+socitem[i].thingId+"</td></tr>"; content = content + "<tr><td> 经纬度:"+socitem[i].longitudedirectionValue+socitem[i].longitude+","+socitem[i].latitudedirectionValue+socitem[i].latitude+"</td></tr>"; content = content + "<tr><td> 与最新点距离:"+distance.toFixed(2)+"m</td></tr>"; content = content + "<tr><td> 时间:"+socitem[i].uploadTime+"</td></tr>"; content += "</table>"; //调用创建marker标记的方法, var marker = this.createMarker( point, content, socitem[i].thingId, i, myIcon ); map.addOverlay(marker) // 将标注添加到地图中 var circle = new BMap.Circle(point, 6, { strokeColor: 'Red', strokeWeight: 8, strokeOpacity: 2, Color: 'Blue', fillColor: '#f03' }) map.addOverlay(circle) } } else { console.log('没有数据的显示') this.soctitle = '暂无数据显示' } } else { console.log('没有数据的显示') this.noneTitle = '没有数据~' } //绘制箭头及其样式 var sy = new BMap.Symbol(BMap_Symbol_SHAPE_BACKWARD_OPEN_ARROW, { scale: 0.3,//图标缩放大小 strokeColor:'#fff',//设置矢量图标的线填充颜色 strokeWeight: 1//设置线宽 }); var icons = new BMap.IconSequence(sy, '100%', '5%',false);//设置为true,可以对轨迹进行编辑 //画轨迹 var polyLine = new BMap.Polyline(arrPois, { strokeWeight: 2, //宽度 strokeOpacity: 0.5, //透明度,取值范围0 - 1 strokeColor:"#303133",//设置颜色 #4C7FED #303133 #18a45b enableEditing: false,//是否启用线编辑,默认为false enableClicking: false,//是否响应点击事件,默认为true icons:[icons] }); map.addOverlay(polyLine); //画轨迹结束 BMapLib.LuShu.prototype._move = function(initPos, targetPos, effect) { var pointsArr = [initPos, targetPos]; //点数组 var me = this, //当前的帧数 currentCount = 0, //步长,米/秒 timer = 10, step = this._opts.speed / (1000 / timer), //初始坐标 init_pos = this._projection.lngLatToPoint(initPos), //获取结束点的(x,y)坐标 target_pos = this._projection.lngLatToPoint(targetPos), //总的步长 count = Math.round(me._getDistance(init_pos, target_pos) / step); //显示折线 //如果想显示小车走过的痕迹,放开这段代码就行 this._map.addOverlay( new BMap.Polyline(pointsArr, { strokeColor: "#111", strokeWeight: 3, strokeOpacity: 0.5 }) ); // 画线 //如果小于1直接移动到下一点 if (count < 1) { me._moveNext(++me.i); return; } me._intervalFlag = setInterval(function() { //两点之间当前帧数大于总帧数的时候,则说明已经完成移动 if (currentCount >= count) { clearInterval(me._intervalFlag); //移动的点已经超过总的长度 if (me.i > me._path.length) { return; } //运行下一个点 me._moveNext(++me.i); } else { currentCount++; var x = effect(init_pos.x, target_pos.x, currentCount, count), y = effect(init_pos.y, target_pos.y, currentCount, count), pos = me._projection.pointToLngLat(new BMap.Pixel(x, y)); //设置marker if (currentCount == 1) { var proPos = null; if (me.i - 1 >= 0) { proPos = me._path[me.i - 1]; } if (me._opts.enableRotation == true) { me.setRotation(proPos, initPos, targetPos); } if (me._opts.autoView) { if (!me._map.getBounds().containsPoint(pos)) { me._map.setCenter(pos); } } } //正在移动 me._marker.setPosition(pos); //设置自定义overlay的位置 me._setInfoWin(pos); } }, timer); }; //添加缩略图控件 map.addControl(new BMap.OverviewMapControl({isOpen:true,anchor:BMAP_ANCHOR_BOTTOM_RIGHT})); //添加缩放平移控件 map.addControl(new BMap.NavigationControl()); //添加比例尺控件 map.addControl(new BMap.ScaleControl({anchor:BMAP_ANCHOR_TOP_LEFT})); //添加地图类型控件 // map.addControl(new BMap.MapTypeControl()); // 普通街道视图:BMAP_NORMAL_MAP // 三维视图:BMAP_PERSPECTIVE_MAP // 卫星视图:BMAP_SATELLITE_MAP // 卫星和路网的混合视图:BMAP_HYBRID_MAP map.addControl(new BMap.MapTypeControl({mapTypes: [BMAP_NORMAL_MAP,BMAP_SATELLITE_MAP],anchor: BMAP_ANCHOR_TOP_RIGHT})); //负责切换地图类型的控件 this.initLushu(map, arrPois, this.batteryId); }) }) }, // 测量百度地图两个点间的距离 /* * Lat1 Lung1 表示A点经纬度,Lat2 Lung2 表示B点经纬度; a=Lat1 – Lat2 为两点纬度之差 b=Lung1 * -Lung2 为两点经度之差; * 6378.137为地球半径,单位为公里; * 最新平均半径 大约3959英里(6371.393千米) 。这个数字是地心到地球表面所有各点距离的平均值。 可以这样求:平均半径=(赤道半径&times;2+极半径)/3 地球半径有时被使用作为距离单位, 特别是在天文学和地质学中常用。它通常用RE表示。 地球大概半径6370.856千米。 * 计算出来的结果单位为公里。 * 经过经纬度获取距离(单位:公里) * @param lat1 * @param lng1 * @param lat2 * @param lng2 * @return */ getDistance(lat1,lng1,lat2,lng2) { let EARTH_RADIUS = 6378.137; let radLat1 = this.rad(lat1); let radLat2 = this.rad(lat2); let a = radLat1 - radLat2; let b = this.rad(lng1) - this.rad(lng2); let s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2))); s = s * EARTH_RADIUS; s = Math.round(s * 10000) / 10000; s = s*1000; //乘以1000是换算成米 return s; }, rad(d){ return d * Math.PI / 180.0; }, initLushu(map, arrPois, batteryId) { this.lushu = new BMapLib.LuShu(map, arrPois, { defaultContent: batteryId, // autoView: true, //是否开启自动视野调整,如果开启那么路书在运动过程中会根据视野自动调整 icon: new BMap.Icon( require("../../../assets/img/mybike2.png"), new BMap.Size(52, 26), { anchor: new BMap.Size(27, 13) } ), speed: this.speed, enableRotation: true, //是否设置marker随着道路的走向进行旋转 landmarkPois: [ { lng:114.52785300795644, lat:38.14758574827796, html: "加油站", pauseTime: 2 } ] }); }, play(val) { // 动图播放 if (this.arrIndex >= this.gpsArr.length - 3) { this.arrIndex = 0; } switch (val) { case 1: this.lushu.start(); break; case 2: this.lushu.pause(); break; case 3: this.lushu.stop(); this.arrIndex = 0; this.percentage = 0; break; } }, //创建maeker和infowindow //传入的参数为:坐标,弹框中要显示的信息,厂区号 createMarker(point, iw, paramNumber,i,myIcon) { var markerx = new BMap.Marker(point); //序号为1.2.3.4.....,根据需求更改 var label = new BMap.Label(i+1, { offset:new BMap.Size(-3,-5)}); label.setStyle({ background:'url()', color:'#fff', border:'none', fontSize:'12px', textAlign:'center', width:'25px', height:'25px', lineHeight:'25px' }); markerx.setLabel(label) //将序号放入标记中 markerx.setZIndex(9999) //在路线之上 覆盖路线 var opts = { width: 300, // 信息窗口宽度 height: 180, // 信息窗口高度 title: '<h4>坐标信息'+'</h4>', // 信息窗口标题 enableMessage: true, //设置允许信息窗发送短息 message: "" } //鼠标停留发生的事件 markerx.addEventListener("mouseover", function(e) { this.openInfoWindow(new BMap.InfoWindow(iw,opts)); }); //鼠标划出发生的事件 markerx.addEventListener("mouseout", function(e) { this.closeInfoWindow(new BMap.InfoWindow(iw)); }); //点击标记发生的事件,暂不做特殊处理 var that = this; markerx.addEventListener("click", function(e) { }); return markerx; } }} <style > /* 弹出框中标题样式 */ .title { color: darkgreen; text-align: center; height: 0.125rem; } /* 弹出框中提示“无数据”的样式 */ .nodate { color: dimgrey; text-align: center; } /* 弹出框底部的点击提示样式 */ .reminder { font-size: 0.15rem; color: darkcyan; margin-left: 1.25rem; } .btn { width: 1.125rem; height: 0.375rem; float: left; background-color: #fff; color: rgba(27, 142, 236, 1); font-size: 0.175rem; border:0.0125rem solid rgba(27, 142, 236, 1); border-radius: 0.0625rem; margin: 0 0.0625rem; text-align: center; line-height: 0.375rem; } .btn:hover { background-color: rgba(27, 142, 236, 0.8); color: #fff; } .drawing-panel { z-index: 999; position: fixed; bottom: 1.3rem; margin-left: 0.3rem; padding: 0.12rem 0.12rem; border-radius: .05rem; background-color: #fff; box-shadow: 0 0.025rem 0.075rem 0 rgba(27, 142, 236, 0.5); } /* 以下为坐标 弹框信息的样式 */ /*地图标题*/ /* 去除百度地图版权那行字 和 百度logo */ .BMap_bubble_title { color: white; font-size: 0.1625rem; font-weight: bold; text-align: left; padding-left: 0.0625rem; padding-top: 0.0625rem; border-bottom: 0.0125rem solid gray; background-color: #409EFF; } /* 消息内容 */ .BMap_bubble_content { background-color: rgba(40, 40, 40, 0.8); padding-left: 0.0625rem; padding-top: 0.0625rem; padding-bottom: 0.125rem; border-bottom-left-radius: 0.1rem; border-bottom-right-radius: 0.1rem; } /* 内容 */ .BMap_pop div:nth-child(9) { top: 0.4375rem !important; border-radius: 0.0625rem; } .BMap_pop div:nth-child(5) { display: none; } /* 左上角删除按键 */ .BMap_pop img { display: none; } .BMap_top { display: none; } .BMap_bottom { display: none; } .BMap_center { display: none; } /* 隐藏边角 */ .BMap_pop div:nth-child(1) div { display: none; } .BMap_pop div:nth-child(3) { display: none; } .BMap_pop div:nth-child(7) { display: none; } </style>在顶部添加两个时间范围筛选作为入参,并且去掉点位图标,鼠标靠近就显示对应点位卡片信息,避免[Vue warn]: Error in v-on handler: "TypeError: Cannot read properties of undefined (reading 'BMap')",改完后,给我完整的代码
08-21
vue.esm.js:629 [Vue warn]: Error in v-on handler: "TypeError: Cannot read properties of undefined (reading 'BMap')" found in ---> <ElButton> at packages/button/src/button.vue <BmMap> <BtAddrBaiDu> at src\views\modules\battery\mymqttequdetailsguiji.vue <ElMain> at packages/main/src/main.vue <ElContainer> at packages/container/src/main.vue <ElDialog> at packages/dialog/src/component.vue <Mymqttequdetails> at src\views\modules\battery\mymqttequdetails.vue <HomeNew2> at src\views\common\home_new2.vue <ElCard> at packages/card/src/main.vue <MainContent> at src\views\main-content3.vue <Main> at src\views\main.vue <App> at src\App.vue <Root>报错,分析代码如何修复正确:<template> <div> <baidu-map id="allmap" :center="center" :zoom="zoom" @ready="handler" style="height:9.45rem;width: 100%;" @click="getClickInfo" :scroll-wheel-zoom='true'> <div class="drawing-panel" style="z-index: 99;"> <button class = "btn" @click='play(1)' size="small">播放</button> <button class = "btn" @click='play(2)' size="small">暂停</button> <button class = "btn" @click='play(3)' size="small">停止</button> <!-- 时间筛选工具栏 --> <div> <div class="time-filter"> <el-date-picker v-model="startTime" type="datetime" placeholder="开始时间" format=yyyy-MM-dd HH:mm:ss value-format=yyyy-MM-dd HH:mm:ss /> <el-date-picker v-model="endTime" type="datetime" placeholder="结束时间" format=yyyy-MM-dd HH:mm:ss value-format=yyyy-MM-dd HH:mm:ss /> <el-button type="primary" @click="searchConfirm">查询</el-button> </div> </div> </div> </baidu-map> </div> </template> <script> export default { name: 'BtAddrBaiDu', data () { return { startTime: null, // 新增:开始时间 endTime: null, // 新增:结束时间 center: {lng: 114.085947, lat: 22.547}, zoom: 15, // 地图缩放比例,越大越细 point:"", gpsArr:[ { lng:114.000069, lat:22.500069 }, // { // lng:114.54050114953694, // lat:38.13759635572114 // }, // { // lng:114.56579743269792, // lat:38.12419932394176 // }, // { // lng:114.5908781225365, // lat:38.12056580319661 // }, // { // lng:114.6115750814864, // lat:38.11613720325717 // }, ],//后台拿到的gps点数组 speed:500,//速度 lushu:{},//路书 batteryId:"电池编号:"+this.$parent.$children[0].hwid, myMap: {} //地图 } }, mounted(){ this.handler(); // 函数调用 }, methods: { searchConfirm() { this.handler(); console.log("============") }, handler({BMap, map}){ this.$nextTick(()=>{ this.$http({ url: this.$http.adornUrl('/mqtt/mtgpslocationinfo/queryGpsLocationInfos'), method: 'get', params: this.$http.adornParams({ 'thingid': this.$parent.$children[0].hwid, //从父类的一个子类中获取hwid,子类中的hwid都是一样的 this.detailsparentmsg 'startTime': this.startTime, 'endTime': this.endTime }) }).then(({data}) => { //无论有无数,都要画出地图 map.enableScrollWheelZoom(new BMap.Point(114.085947, 22.547), 15); map.centerAndZoom(); var arrPois = []; if (data && data.code === 0) { const socitem = data.data if (socitem && socitem.length > 0) { let clng = socitem[socitem.length-1].longitude; let clat = socitem[socitem.length-1].latitude; // this.center = {lng: socitem[socitem.length-1].longitude, lat: socitem[socitem.length-1].latitude}; // 以最新经纬度为中心 this.center = {lng: clng, lat: clat}; //下方为打点代码------------------------------------------------- // var nowIcon = new BMap.Icon( // require("../../../assets/img/guiji2.png"), // new BMap.Size(47, 47), // { // anchor: new BMap.Size(22, 40), // imageOffset: new BMap.Size(0, 0) // } // ); // var myIcon = new BMap.Icon( // "http://developer.baidu.com/map/jsdemo/img/car.png", // new BMap.Size(52, 26), // { // anchor: new BMap.Size(27, 13) // } // ); //http://map.baidu.com/image/us_mk_icon.png //说明:要使用不同的图片,只需要修改图片偏移就可以了,第一行第一列图片是(0, 0 - 0 * 25),第二行第一列图片是(0, 0 - 1 * 25)......以此类推就可以了 var myIcon = new BMap.Icon( require("../../../assets/img/markers.png"), // "http://api.map.baidu.com/img/markers.png", new BMap.Size(23, 25), { offset: new BMap.Size(10, 25), // 指定定位位置 imageOffset: new BMap.Size(0, 0 - 11 * 25) // 设置图片偏移 }); //打点图标样式------------------------------------------------------ for (let i = 0; i < socitem.length; i++) { var p0 = socitem[i].longitude; var p1 = socitem[i].latitude; // var checksum = makerArry[i].checksum; var point = new BMap.Point(p0, p1); //118.230272,33.482474 arrPois.push(point); //距离差距 var distance = this.getDistance(clat,clng, p1,p0); var content = "<table style='color: #FFF;'>"; // content = content + "<tr><td> 电池编号:"+socitem[i].hwid+"</td></tr>"; // content = content + "<tr><td> 所属:"+socitem[i].describe+"</td></tr>"; // content = content + "<tr><td> 经纬度:"+socitem[i].longitudeMark+socitem[i].longitude+","+socitem[i].latitudeMark+socitem[i].latitude+"</td></tr>"; // content = content + "<tr><td> 与最新点距离:"+distance.toFixed(2)+"m</td></tr>"; // content = content + "<tr><td> 时间:"+socitem[i].modifyTime+"</td></tr>"; // content += "</table>"; content = content + "<tr><td> 电池编号:"+socitem[i].thingId+"</td></tr>"; // content = content + "<tr><td> 电量:"+socitem[i].soc+" %</td></tr>"; content = content + "<tr><td> 经纬度:"+socitem[i].longitudedirectionValue+socitem[i].longitude+","+socitem[i].latitudedirectionValue+socitem[i].latitude+"</td></tr>"; content = content + "<tr><td> 与最新点距离:"+distance.toFixed(2)+"m</td></tr>"; content = content + "<tr><td> 时间:"+socitem[i].uploadTime+"</td></tr>"; content += "</table>"; // var infoMessage = "<br><div class='nodate'>无数据!</div><br><span class='reminder'>点击标记获取更多信息</span>"; //调用创建marker标记的方法, var marker = this.createMarker( point, content, socitem[i].thingId, i, myIcon ); map.addOverlay(marker) // 将标注添加到地图中 var circle = new BMap.Circle(point, 6, { strokeColor: 'Red', strokeWeight: 8, strokeOpacity: 2, Color: 'Blue', fillColor: '#f03' }) map.addOverlay(circle) } } else { console.log('没有数据的显示') this.soctitle = '暂无数据显示' } } else { console.log('没有数据的显示') this.noneTitle = '没有数据~' } //绘制箭头及其样式 var sy = new BMap.Symbol(BMap_Symbol_SHAPE_BACKWARD_OPEN_ARROW, { scale: 0.3,//图标缩放大小 strokeColor:'#fff',//设置矢量图标的线填充颜色 strokeWeight: 1//设置线宽 }); var icons = new BMap.IconSequence(sy, '100%', '5%',false);//设置为true,可以对轨迹进行编辑 //画轨迹 var polyLine = new BMap.Polyline(arrPois, { // strokeColor: "blue", //设置颜色 strokeWeight: 2, //宽度 strokeOpacity: 0.5, //透明度,取值范围0 - 1 strokeColor:"#303133",//设置颜色 #4C7FED #303133 #18a45b enableEditing: false,//是否启用线编辑,默认为false enableClicking: false,//是否响应点击事件,默认为true icons:[icons] }); map.addOverlay(polyLine); //画轨迹结束 BMapLib.LuShu.prototype._move = function(initPos, targetPos, effect) { var pointsArr = [initPos, targetPos]; //点数组 var me = this, //当前的帧数 currentCount = 0, //步长,米/秒 timer = 10, step = this._opts.speed / (1000 / timer), //初始坐标 init_pos = this._projection.lngLatToPoint(initPos), //获取结束点的(x,y)坐标 target_pos = this._projection.lngLatToPoint(targetPos), //总的步长 count = Math.round(me._getDistance(init_pos, target_pos) / step); //显示折线 //如果想显示小车走过的痕迹,放开这段代码就行 this._map.addOverlay( new BMap.Polyline(pointsArr, { strokeColor: "#111", strokeWeight: 3, strokeOpacity: 0.5 }) ); // 画线 //如果小于1直接移动到下一点 if (count < 1) { // alert(count < 1); me._moveNext(++me.i); return; } // alert(count); me._intervalFlag = setInterval(function() { //两点之间当前帧数大于总帧数的时候,则说明已经完成移动 if (currentCount >= count) { clearInterval(me._intervalFlag); //移动的点已经超过总的长度 if (me.i > me._path.length) { return; } //运行下一个点 me._moveNext(++me.i); } else { currentCount++; var x = effect(init_pos.x, target_pos.x, currentCount, count), y = effect(init_pos.y, target_pos.y, currentCount, count), pos = me._projection.pointToLngLat(new BMap.Pixel(x, y)); //设置marker if (currentCount == 1) { var proPos = null; if (me.i - 1 >= 0) { proPos = me._path[me.i - 1]; } if (me._opts.enableRotation == true) { me.setRotation(proPos, initPos, targetPos); } if (me._opts.autoView) { if (!me._map.getBounds().containsPoint(pos)) { me._map.setCenter(pos); } } } //正在移动 me._marker.setPosition(pos); //设置自定义overlay的位置 me._setInfoWin(pos); } }, timer); }; // BMAP_ANCHOR_TOP_LEFT 表示控件定位于地图的左上角。 // BMAP_ANCHOR_TOP_RIGHT 表示控件定位于地图的右上角。 // BMAP_ANCHOR_BOTTOM_LEFT 表示控件定位于地图的左下角。 // BMAP_ANCHOR_BOTTOM_RIGHT 表示控件定位于地图的右下角。 //添加地图类型控件 // map.addControl(new BMap.MapTypeControl({anchor: BMAP_ANCHOR_TOP_RIGHT}));//右上角,默认地图控件 //地图混合 // map.addControl(new BMap.MapTypeControl({ // mapTypes:[ // BMAP_NORMAL_MAP, // BMAP_HYBRID_MAP // ]})); //添加缩略图控件 map.addControl(new BMap.OverviewMapControl({isOpen:true,anchor:BMAP_ANCHOR_BOTTOM_RIGHT})); //添加缩放平移控件 map.addControl(new BMap.NavigationControl()); //添加比例尺控件 map.addControl(new BMap.ScaleControl({anchor:BMAP_ANCHOR_TOP_LEFT})); //添加地图类型控件 // map.addControl(new BMap.MapTypeControl()); // 普通街道视图:BMAP_NORMAL_MAP // 三维视图:BMAP_PERSPECTIVE_MAP // 卫星视图:BMAP_SATELLITE_MAP // 卫星和路网的混合视图:BMAP_HYBRID_MAP map.addControl(new BMap.MapTypeControl({mapTypes: [BMAP_NORMAL_MAP,BMAP_SATELLITE_MAP],anchor: BMAP_ANCHOR_TOP_RIGHT})); //负责切换地图类型的控件 this.initLushu(map, arrPois, this.batteryId); // map.addEventListener('tilesloaded', function () { // alert('地图加载完成!'); // }); }) }) }, // 测量百度地图两个点间的距离 // getDistance (itemPoint) { // var map = new BMap.Map('') // var pointB = new BMap.Point(parseFloat(itemPoint.log), parseFloat(itemPoint.lat)) // 店铺的经纬度 // var distance = (map.getDistance(this.pointA, pointB) / 1000).toFixed(2) // 保留小数点后两位 // return distance // }, /* * Lat1 Lung1 表示A点经纬度,Lat2 Lung2 表示B点经纬度; a=Lat1 – Lat2 为两点纬度之差 b=Lung1 * -Lung2 为两点经度之差; * 6378.137为地球半径,单位为公里; * 最新平均半径 大约3959英里(6371.393千米) 。这个数字是地心到地球表面所有各点距离的平均值。 可以这样求:平均半径=(赤道半径&times;2+极半径)/3 地球半径有时被使用作为距离单位, 特别是在天文学和地质学中常用。它通常用RE表示。 地球大概半径6370.856千米。 * 计算出来的结果单位为公里。 * 经过经纬度获取距离(单位:公里) * @param lat1 * @param lng1 * @param lat2 * @param lng2 * @return */ getDistance(lat1,lng1,lat2,lng2) { let EARTH_RADIUS = 6378.137; let radLat1 = this.rad(lat1); let radLat2 = this.rad(lat2); let a = radLat1 - radLat2; let b = this.rad(lng1) - this.rad(lng2); let s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2))); s = s * EARTH_RADIUS; // s = Math.round(s * 10000d) / 10000d; s = Math.round(s * 10000) / 10000; s = s*1000; //乘以1000是换算成米 return s; }, rad(d){ return d * Math.PI / 180.0; }, initLushu(map, arrPois, batteryId) { this.lushu = new BMapLib.LuShu(map, arrPois, { defaultContent: batteryId, // autoView: true, //是否开启自动视野调整,如果开启那么路书在运动过程中会根据视野自动调整 icon: new BMap.Icon( require("../../../assets/img/mybike2.png"), // "http://developer.baidu.com/map/jsdemo/img/car.png", // http://webapi.amap.com/images/car.png ~@/assets/img/car.png http://developer.baidu.com/map/jsdemo/img/fox.gif http://developer.baidu.com/map/jsdemo/img/car.png new BMap.Size(52, 26), { anchor: new BMap.Size(27, 13) } ), // icon: new BMap.Icon("http://developer.baidu.com/map/jsdemo/img/fox.gif", new BMap.Size(300,157)), speed: this.speed, enableRotation: true, //是否设置marker随着道路的走向进行旋转 landmarkPois: [ { lng:114.52785300795644, lat:38.14758574827796, html: "加油站", pauseTime: 2 } ] }); }, play(val) { // 动图播放 if (this.arrIndex >= this.gpsArr.length - 3) { this.arrIndex = 0; } switch (val) { case 1: this.lushu.start(); break; case 2: this.lushu.pause(); break; case 3: this.lushu.stop(); this.arrIndex = 0; this.percentage = 0; break; } }, //创建maeker和infowindow //传入的参数为:坐标,弹框中要显示的信息,厂区号 createMarker(point, iw, paramNumber,i,myIcon) { // var markerx = new BMap.Marker(point,{icon:myIcon}); var markerx = new BMap.Marker(point); //序号为1.2.3.4.....,根据需求更改 var label = new BMap.Label(i+1, { offset:new BMap.Size(-3,-5)}); label.setStyle({ background:'url()', // ~@/assets/img/guiji2.png color:'#fff', border:'none', fontSize:'12px', textAlign:'center', width:'25px', height:'25px', lineHeight:'25px' }); markerx.setLabel(label) //将序号放入标记中 markerx.setZIndex(9999) //在路线之上 覆盖路线 var opts = { width: 300, // 信息窗口宽度 height: 180, // 信息窗口高度 title: '<h4>坐标信息'+'</h4>', // 信息窗口标题 enableMessage: true, //设置允许信息窗发送短息 message: "" } //鼠标停留发生的事件 markerx.addEventListener("mouseover", function(e) { this.openInfoWindow(new BMap.InfoWindow(iw,opts)); // alert("mouseover==="+iw); }); //鼠标划出发生的事件 markerx.addEventListener("mouseout", function(e) { this.closeInfoWindow(new BMap.InfoWindow(iw)); }); //点击标记发生的事件,暂不做特殊处理 var that = this; markerx.addEventListener("click", function(e) { // this.openInfoWindow(new BMap.InfoWindow(iw,opts)); // that.$router.push({ // path: "home", // query: { // paramnumber: paramNumber // }//给跳转页面传递的参数 // }); }); return markerx; } }} </script> <style > /* 去除百度地图版权那行字 和 百度logo */ /* .BMap_cpyCtrl { display: none!important; } */ /* .anchorBL { display: none!important; } */ /* 弹出框中标题样式 */ .title { color: darkgreen; text-align: center; height: 0.125rem; } /* 弹出框中提示“无数据”的样式 */ .nodate { color: dimgrey; text-align: center; } /* 弹出框底部的点击提示样式 */ .reminder { font-size: 0.15rem; color: darkcyan; margin-left: 1.25rem; } .btn { width: 1.125rem; height: 0.375rem; float: left; background-color: #fff; color: rgba(27, 142, 236, 1); font-size: 0.175rem; border:0.0125rem solid rgba(27, 142, 236, 1); border-radius: 0.0625rem; margin: 0 0.0625rem; text-align: center; line-height: 0.375rem; } .btn:hover { background-color: rgba(27, 142, 236, 0.8); color: #fff; } .drawing-panel { z-index: 999; position: fixed; bottom: 1.3rem; margin-left: 0.3rem; padding: 0.12rem 0.12rem; border-radius: .05rem; background-color: #fff; box-shadow: 0 0.025rem 0.075rem 0 rgba(27, 142, 236, 0.5); } /* 以下为坐标 弹框信息的样式 */ /*地图标题*/ /* 去除百度地图版权那行字 和 百度logo */ /* .anchorBL, .BMap_cpyCtrl { display: none; } */ .BMap_bubble_title { color: white; font-size: 0.1625rem; font-weight: bold; text-align: left; padding-left: 0.0625rem; padding-top: 0.0625rem; border-bottom: 0.0125rem solid gray; background-color: #409EFF; } /* 消息内容 */ .BMap_bubble_content { background-color: rgba(40, 40, 40, 0.8); padding-left: 0.0625rem; padding-top: 0.0625rem; padding-bottom: 0.125rem; border-bottom-left-radius: 0.1rem; border-bottom-right-radius: 0.1rem; } /* 内容 */ .BMap_pop div:nth-child(9) { top: 0.4375rem !important; border-radius: 0.0625rem; } .BMap_pop div:nth-child(5) { display: none; } /* 左上角删除按键 */ .BMap_pop img { /* // top: 43px !important; // left: 215px !important; */ display: none; } .BMap_top { display: none; } .BMap_bottom { display: none; } .BMap_center { display: none; } /* 隐藏边角 */ .BMap_pop div:nth-child(1) div { display: none; } .BMap_pop div:nth-child(3) { display: none; } .BMap_pop div:nth-child(7) { display: none; } </style>
08-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值