gpt4 book ai didi

javascript - 如何在 vuejs+electron 中调用 'export default' 范围之外的方法?

转载 作者:行者123 更新时间:2023-12-01 00:30:33 25 4
gpt4 key购买 nike

当我通过拖动标题栏最大化窗口时,电子会发出“最大化”事件。我想调用“导出默认”范围内存在的“最大化”方法。我怎样才能打电话?

<template>
<div class="window-titlebar">
<div class="title">{{ title }}</div>
</div>
</template>

<script>
const electron = require('electron');
import { ipcRenderer } from 'electron';

export default {
name: 'window-titlebar',
data() {
return {
title: false
}
},
methods: {
maximize: function() {
this.title = true;
}
}

}

ipcRenderer.on('maximize', () => {
// I want to call 'maximize' method here
})

</script>

最佳答案

最好在组件本身上注册事件处理程序,这样您就可以将事件处理程序的存在与组件的生命周期联系起来,并且事件处理程序将在组件实例的上下文中执行。

export default {
name: 'window-titlebar',
data() {
return {
title: false
}
},
created() {
ipcRenderer.on('maximize', this.onMaximize)
},
destroyed() {
ipcRenderer.off('maximize', this.onMaximize)
},
methods: {
onMaximize() {
this.title = true
}
}
}

关于javascript - 如何在 vuejs+electron 中调用 'export default' 范围之外的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58583445/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com