问题描述
我在客户端上的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 (将#修改为@)