我正在尝试将Vue-socket.IO连接到外部服务器。
import VueSocketIO from 'vue-socket.io'
Vue.use(new VueSocketIO({
debug: true,
connection: 'IPToServer',
vuex: {
store,
actionPrefix: 'SOCKET_',
mutationPrefix: 'SOCKET_'
},
options: { path: '/api' }
}))
在我的组件中:
export default {
sockets: {
connect: function() {
console.log('socket connected')
},
customEmit: function (data) {
console.log('this method was fired by the socket server. eg: io.emit("customEmit", data)')
}
}...
mounted() {
getMainViewObj()
console.log(this.test())
},
methods: {
test() {
this.$socket.emit('request')
}
}
这给了我以下错误:
获取http://IPToServer/api/?EIO=3&transport=polling&t=MeBYeWG网:: ERR_CONNECTION_REFUSED
有人知道这可能是什么问题吗?