this$ socket.emit无法读取未定义的属性发射

问题描述

我在客户端上的socket.io有问题。 Vuejs上的项目,服务器快递,服务器工作良好。 我将socketIo与vue-socket.io

连接
import Vue from "vue";
import "./plugins/axios";
import App from "./App.vue";
import "./registerServiceWorker";
import router from "./router";
import store from "./store";
import vuetify from "./plugins/vuetify";
import VueSocketIO from "vue-socket.io";
import io from "socket.io-client";

const vueSocketIO = new VueSocketIO({
  debug: false,connection: io.connect("http://localhost:3030/"),vuex: {
      store,actionPrefix: 'SOCKET_',mutationPrefix: 'SOCKET_'
  }
});

Vue.use(vueSocketIO);

Vue.config.productionTip = false;

new Vue({
  router,store,vuetify,vueSocketIO,render: h => h(App)
}).$mount("#app");

在聊天组件中,当this.$socket.emit设置方法“发送”时出现错误“无法读取未定义的属性发出”

<script>
import ChatItem from "@/components/chat/ChatItem";
import { mapGetters } from "vuex";

export default {
  name: "Chat",sockets: {
    connect() {
      console.log('socket to notification channel connected')
    },add() {
      console.log('hi')
    }
  },data() {
    return {
      itemData: {
        text: "",name: this.$store.state.loginUser,time: new Date().toLocaleTimeString()
      }
    };
  },components: {
    ChatItem
  },methods: {
    send() {
      let data = {
        text: this.itemData.text,name: this.$store.state.loginUser.split(' ')[0],time: new Date().toLocaleTimeString()
      };
      this.$socket.emit("send",data);
      this.itemData.text = "";
    }
  },computed: mapGetters(["getChatHistory"]),created() {
  }
};
</script>

请帮帮我,我在做什么错了?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...