-1

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

sergey_s
  • 119
  • 2
  • 6

1 Answers1

0

The problem solved when I back to commonJS.

sergey_s
  • 119
  • 2
  • 6