首页 > 解决方案 > 使用自定义文件在 VueJS CLI 应用程序中实现 Socket.IO

问题描述

好的,在下面的链接中,您将找到 ccc-streamer-utilities.js 和一个名为 streamer 的文件夹,其中包含一个 stream.js 文件。

这是链接

stream.js 管理 websocket 连接,而 ccc-streamer-utilites.js 装饰输出并提供帮助函数。

我需要做的是包含以下文件并在 Vue CLI 应用程序中使用它们。但是,我在尝试这样做时遇到了很多困难。在尝试了一周并在 reddit 上询问后,我来了。

这就是 main.js 文件的样子。如果帮助不是您倾向于做的事情,请指出我正确的方向。

import Vue from 'vue'
import App from './App.vue'
import router from './router'
import Vuetify from 'vuetify'
import 'vuetify/dist/vuetify.min.css'
import VueSocketIO from 'vue-socket.io' //VueJS socket component
import io from 'socket.io-client' //Socket import

Vue.use(Vuetify, VueSocketIO, socket)
Vue.config.productionTip = false

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')

该组件看起来像这样

<template>
  <div id="app">
    <div> ... (socket output is determined by element classes and divs [check the two files for more information on this] so ideally, I'd have an implementation that allows me to just input the right class and id's to get the result i want) </div>
  </div>
</template>
.....

这是我几个月前在原型设计时所做的不使用 VueJS 的客户端实现。

非常感谢您抽出时间在这里真正帮助我,因为我知道我要求很多。

我的问题:如何在 VueJS 的单个文件组件中实现 stream.js 和 ccc-streamer-utilities.js 提供的实用程序?

标签: javascriptvue.jssocket.io

解决方案


推荐阅读