目前需要解決的問題有兩個:
1、調用 ActiveX 控件函數
傳統方式,如下。
document.getElementById('objMqtt').init()
其他方式,未考證。
參考鏈接:https://forum.vuejs.org/t/vue-ocx-vue/20324/6
參考鏈接:https://www.jianshu.com/p/5f9c6f05cda1
2、Vue.js 與 ActiveX 事件
方法一:使用 attachEvent 或者 addEventListener 方法。
據說在IE8-10可用,不過未能實現。
參考鏈接:https://blog.csdn.net/youyouwoxing1991/article/details/88649638
方法二:動態生成腳本,渲染到頁面上。IE 9-11,測試成功。
1.在methods中,新增事件觸法的方法。
wakeUp(msg) { console.log('receive:' + msg) }
2.在methods中,新增方法,用於動態生成ActiveX控件事件綁定。
initActiveXObject () { var scriptStr = document.createElement('script') scriptStr.setAttribute('for', 'obj1') scriptStr.event = 'UserStopInfo(strMsg)' scriptStr.appendChild(document.createTextNode(activeXListener.wakeUp(strMsg)')) document.body.appendChild(scriptStr) window.activeXListener = this }
3.在mouted方法中,初始化ActiveX控件。
mounted () { this.initActiveXObject() }