日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

Qt工作笔记-WebEngineView调用web站点中的JS脚本(含Vue Cli脚本)

發布時間:2025/3/15 vue 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Qt工作笔记-WebEngineView调用web站点中的JS脚本(含Vue Cli脚本) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

首先是一個例子,網頁結構如下:

代碼如下:

index.html

<html> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> <head> </head><body> <h1>Hello World</h1> <script type="text/javascript" src="js.js"></script><script type="text/javascript">function callFunctionDemo(){alert("Hello World");}</script></body></html>

js.js

;function jsFileCall(){alert("jsFileCall"); }function jsFileCall2(str){alert("str:" + str);return str; }

qml是這樣的代碼:

import QtQuick 2.5 import QtQuick.Window 2.2 import QtWebEngine 1.0 import QtQuick.Controls 1.4Window {visible: truewidth: 640height: 480WebEngineView{id: webanchors.fill: parenturl: "http://127.0.0.1:9998/"}Button {text: "Button"onClicked: {/*var functionStr = "callFunctionDemo()";web.runJavaScript(functionStr, function(result){console.log(result);});*/var functionStr = "jsFileCall()";web.runJavaScript(functionStr, function(result){console.log(String(result));});}} }

點擊按鈕后:

當是這樣的代碼:

import QtQuick 2.5 import QtQuick.Window 2.2 import QtWebEngine 1.0 import QtQuick.Controls 1.4Window {visible: truewidth: 640height: 480WebEngineView{id: webanchors.fill: parenturl: "http://127.0.0.1:9998/"}Button {text: "Button"onClicked: {/*var functionStr = "callFunctionDemo()";web.runJavaScript(functionStr, function(result){console.log(result);});*/var functionStr = "jsFileCall2(12345)";web.runJavaScript(functionStr, function(result){console.log(String(result));});}} }

點擊按鈕后:

qml接受到的數據

下面還有種情況,當前端是vue?cli的時候。這里就簡單提一下了。

在xxx.vue中的mounted中添加window.xxxx=this;這樣在控制臺使用window.xxx.zzzz這個zzzz就是對應vue中的methods的函數,然后再qml中這樣修改即可。

?

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的Qt工作笔记-WebEngineView调用web站点中的JS脚本(含Vue Cli脚本)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。