【发布时间】:2021-04-30 01:18:36
【问题描述】:
知道我将如何使用这个插件吗? https://github.com/DimanVorosh/vue-json-rpc-websocket/blob/e2199d89dc15f50e57e7c5c70adfd95e5ceb5cda/src/wsMain.js
我看到它正在自动注册到 vue,但我不能在 nuxt 中使用它。
我创建了plugins/vue-json-rpc-websocket.client.js,在nuxt.config.js注册为
'~/plugins/vue-json-rpc-websocket.client.js'
但我不知道在 inject 方法中写什么,如果我必须这样做才能使其工作。 this.$socket 在组件中未定义。
import Vue from 'vue'
import JRPCWS from 'vue-json-rpc-websocket'
Vue.use(JRPCWS, 'wss://bsc-ws-node.nariox.org:443', {
reconnectEnabled: true,
reconnectInterval: 5000,
reconnectAttempts: 3
})
// do I need this?
export default ({ app }, inject) => {
// Inject $hello(msg) in Vue, context and store.
// inject('hello', msg => console.log(`Hello ${msg}!`))
}
另外,知道如何对'wss://bsc-ws-node.nariox.org:443' 字符串进行 ENV 编码吗?
【问题讨论】:
-
对于 ENV 部分,你看过这个吗? cli.vuejs.org/guide/mode-and-env.html#environment-variables