I have component page. I need connect websocket after page ready;
<script lang="ts">
import Vue from 'vue'
import VueNativeSock from 'vue-native-websocket'
export default Vue.extend({
data() {
return {}
},
methods : {
senddata() {
this.$socket.sendObj({awesome: 'data'})
},
},
mounted(){
Vue.use(VueNativeSock, 'ws://cm2:3000', {
reconnection: true, // (Boolean) whether to reconnect automatically (false)
reconnectionAttempts: 5, // (Number) number of reconnection attempts before giving up (Infinity),
reconnectionDelay: 2000, // (Number) how long to initially wait before attempting a new (1000)
})
}
})
</script>
Everything connects fine, but if I try use $socket in method, I get error while building :
ERROR ERROR in pages/index.vue:20:9 15:42:05
TS2339: Property '$socket' does not exist on type 'CombinedVueInstance<Vue, {}, { senddata(): void; }, unknown, Readonly<Record<never, any>>>'.
18 | senddata() {
19 |
> 20 | this.$socket.sendObj({awesome: 'data'})
| ^^^^^^^
21 |
22 | },
23 |
What do I wrong ? The same if I put wss connection in plugin
question from:
https://stackoverflow.com/questions/65885065/nuxtjs-vue-native-websocket-how-to-use 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…