python EEL + vue3.js 简单示例

把index.html 中引入eel.js 后,eel这个对象就是全局对象了,无论在index.htm中还是组件中,都能使用这个全局对象。

我们组件HelloWorld.vue挂载到组件App.vue上,然后把App.vue挂载到index.html 这样最常见的结构为例:

HelloWorld.vue

//HelloWorld.vue


<script setup>
import { ref } from 'vue'

const count = ref(0)
const message = ref("Hello World!")
 
const sayHelloByEEL = (x) => {
  eel.say_hello_py(x + Math.floor(Math.random() * 101).toString() + 'ee')
}

const sayHelloJS = (x) => {
    message.value = 'Say Hello From ' + Math.floor(Math.random() * 101).toString() +x;
}

//暴露sayHelloJS给Python (以say_hello_js为别名)
eel.expose(sayHelloJS, 'say_hello_js')


</script>

<template>

    <p><button type="button" @click="count++">count is: {
  
  { count }}</button></p>
    <p><button @click="sayHelloByEEL('Javascript Button! ')">调用Python函数</button></p>
    <p>{
  
  { message }}</p>
    <p><button @click="sayHelloJS(' JS Button!')">调用JS函数</button></p>

</template>

<style scoped>

</style>

App.vue

//App.vue

<template>
  <img alt="Vue logo" src="./assets/vue.svg"> python eel + Vue3
  <HelloWorld />
</template>

<script setup>

import H
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值