Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js 安装时通过<;使用Vue.use后出现类型错误;脚本>;_Vue.js_Websocket_Vuejs2 - Fatal编程技术网

Vue.js 安装时通过<;使用Vue.use后出现类型错误;脚本>;

Vue.js 安装时通过<;使用Vue.use后出现类型错误;脚本>;,vue.js,websocket,vuejs2,Vue.js,Websocket,Vuejs2,我必须通过脚本加载vue原生websocket,如 <script src="{% static 'js/vue.js' %}"></script> <script src="{% static 'js/vue-native-websocket.min.js' %}"></script> <script src="{% static 'js/vue_components/OrdersCurrent.js' %}"></

我必须通过脚本加载vue原生websocket,如

  <script src="{% static 'js/vue.js' %}"></script>
  <script src="{% static 'js/vue-native-websocket.min.js' %}"></script>
  <script src="{% static 'js/vue_components/OrdersCurrent.js' %}"></script>
看起来像是
Vue。在这种情况下使用
不工作。我犯了以下错误

vue.js:597 [Vue warn]: Error in created hook: "TypeError: Cannot set property 'onmessage' of undefined"

(found in <Root>)
warn @ vue.js:597
logError @ vue.js:1739
globalHandleError @ vue.js:1734
handleError @ vue.js:1723
callHook @ vue.js:2923
Vue._init @ vue.js:4617
Vue @ vue.js:4716
(anonymous) @ OrdersCurrent.js:8
vue.js:1743 TypeError: Cannot set property 'onmessage' of undefined
    at Vue.created (OrdersCurrent.js:13)
    at callHook (vue.js:2921)
    at Vue._init (vue.js:4617)
    at new Vue (vue.js:4716)
    at OrdersCurrent.js:8
vue.js:597[vue warn]:创建的钩子中出现错误:“TypeError:无法设置未定义的属性“onmessage”
(位于)
warn@vue.js:597
logError@vue.js:1739
globalHandleError@vue.js:1734
handleError@vue.js:1723
callHook@vue.js:2923
Vue._init@Vue.js:4617
Vue@Vue.js:4716
(匿名)@OrdersCurrent.js:8
vue.js:1743 TypeError:无法设置未定义的属性“onmessage”
在Vue.created上(OrdersCurrent.js:13)
在callHook(vue.js:2921)
在Vue._init(Vue.js:4617)
在新Vue(Vue.js:4716)
在OrdersCurrent.js:8

需要使用
VueNativeSock.default
而不是
VueNativeSock
。从CDN安装
vue原生脚本
插件尚未记录在案

Vue.use(VueNativeSock, 'wss://localhost/ws/current-orders/1', {
  reconnection: true,
  reconnectionAttempts: 5,
  reconnectionDelay: 3000,
  format: 'json',
});
Vue.use(VueNativeSock, 'wss://localhost/ws/current-orders/1', {
  reconnection: true,
  reconnectionAttempts: 5,
  reconnectionDelay: 3000,
  format: 'json',
});