vuerouter和vue-socket.io-extended

时间:2019-04-26 21:46:04

标签: vue.js socket.io vue-router

编译vuejs应用程序时收到错误消息。删除与路由器相关的代码行似乎可以解决该错误。鉴于我需要路由器,任何帮助将不胜感激。这是错误:

未捕获的TypeError:无法使用'in'运算符在未定义的位置搜索'onpagehide'     在评估时(polling-xhr.js?d33e:404)     在Object ../ node_modules / engine.io-client / lib / transports / polling-xhr.js(app.js:4389)     在 webpack_require (app.js:724)     在fn(app.js:101)     在评估时(index.js?6a44:6)     在Object ../ node_modules / engine.io-client / lib / transports / index.js(app.js:4367)     在 webpack_require (app.js:724)     在fn(app.js:101)     在评估时(socket.js?da92:5)     在Object ../ node_modules / engine.io-client / lib / socket.js(app.js:4345)

我的目标是连接到外部套接字服务器。我尝试了很多类似的插件,但都带有相同的错误消息。在整个故障排除过程中,当我删除“从'./routes'中导入路由器”时;和“路由器”,我收到控制台消息,说明我已成功连接到套接字服务器。这一定是路由器和套接字插件之间的冲突。

Main.js的内容:

import Vue from 'vue'
import './firebase.js'
import App from './App.vue'
import VueRouter from 'vue-router'
import VueFire from 'vuefire'
import SuiVue from 'semantic-ui-vue';
import 'semantic-ui-css/semantic.min.css';
//import Routes from "./routes";
import VueFlatPickr from 'vue-flatpickr-component';
import 'flatpickr/dist/flatpickr.css';
import firebase from 'firebase';
import router from './routes';
import Toasted from 'vue-toasted';
import VueSocketio from 'vue-socket.io-extended';
import io from 'socket.io-client';

Vue.use(Toasted)
Vue.use(SuiVue);
Vue.use(VueRouter);
Vue.use(VueFire);
Vue.use(VueFlatPickr);
Vue.use(VueSocketio, io('[socket_server_address_here]'));
window.$ = window.jQuery = require('jquery');

let app = '';


  if (!app) {
    /* eslint-disable no-new */
    app = new Vue({
      router,
        sockets: {
    connect() {
      console.log('socket connected')
    },
    customEmit(val) {
      console.log('this method was fired by the socket server. eg: io.emit("customEmit", data)')
    }
  },
      render: h => h(App)
    }).$mount('#app');
  }

我应该收到套接字服务器已连接的控制台消息。

0 个答案:

没有答案