Electron使用指南——11添加一个新的信息
2020-09-01 14:21
786 查看
1、创建 Store
1.1 编辑 store
编辑
/vue-renderer/src/store/index.js:
[code]import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) export default new Vuex.Store({ state: { isShowModal: false }, mutations: { setModalVisible(state, show) { state.isShowModal = show } }, actions: { setModalVisible({commit}, show) { commit('setModalVisible', show) } } })
1.2 引入 store
编辑
/vue-renderer/src/main.js:
[code]// ... import store from './store' // ...
2、显示添加窗口
编辑
/vue-renderer/src/components/Header.vue:
[code]<template> <header> <button id="show-modal" @click="setModalVisible(true)">+</button> // ... </header> </template> <script> import { mapActions } from 'vuex' export default { methods: { ...mapActions(['setModalVisible']) }, } </script>
3、完善添加模态组件
编辑
/vue-renderer/src/components/Modal.vue:
[code]<template> <div id="modal" v-show="isShowModal"> <input type="text" id="url" :disabled="status" v-model="url" placeholder="输入 URL ..."> <button id="add-item" :class="{disabled: status}" :disabled="status" @click="addItem">{{addButtonText}}</button> <button id="close-modal" v-show="!status" @click="setModalVisible(false)">取消</button> </div> </template> <script> import { mapState, mapActions } from 'vuex' export default { data() { return { url: '', status: false, addButtonText: '添加' } }, created() { // Listen for new item from main process ipcRenderer.on('new-item-success', (e, newItem) => { console.log(newItem) this.status = false this.addButtonText = '添加' this.url = '' this.setModalVisible(false) }) }, computed: { ...mapState(['isShowModal']) }, methods: { ...mapActions(['setModalVisible']), addItem() { if (this.url !== '') { // Send new item url to main process ipcRenderer.send('new-item', this.url) this.status = true this.addButtonText = '添加中...' } } } } </script>
4、完善主进程 main.js
编辑
/main.js, 在文件代码中的最外层添加
ipcMain的
new-item时间监听,重点是
ipc通信:
[code]//... // Modules const { ipcMain } = require('electron') // Listen for new item request ipcMain.on('new-item', (e, itemUrl) => { // Get new item and send back to renderer setTimeout(() => { e.sender.send('new-item-success', 'New item from main process') }, 2000) }) // ...
相关文章推荐
- 完成一个学生管理程序,使用学号作为键添加5个学生对象,并可以将全部信息保存在文件中,可以实现对学生信息的学号查找,输出全部学生信息的功能。
- 脚本实现:使用一个用户名做为参数,如果 指定参数的用户存在,就显示其存在,否则添加之;显示添加的用户的id号等 信息
- 完成一个学生管理程序,使用学号作为键添加5个学生对象,并可以将全部信息保存在文件中,可以实现对学生信息的学号查找,输出全部学生信息的功能。
- C#使用Xamarin开发可移植移动应用终章(11.获取设备信息与常用组件,开源一个可开发模版.)
- 11_5_3给people添加GetOldest()方法,使用上面定义的重载运算符,返回一个Age最大的对象数组
- 完成一个学生管理程序,使用学号作为键添加5个学生对象,并可以将全部信息保存在文件中,可以实现对学生信息的学号查找,输出全部学生信息的功能。
- 完成一个学生管理程序,使用学号作为键添加5个学生对象,并可以将全部信息保存在文件中,可以实现对学生信息的学号查找,输出全部学生信息的功能。
- 完成一个学生管理程序,使用学号作为键添加5个学生对象,并可以将全部信息保存在文件中,可以实现对学生信息的学号查找,输出全部学生信息的功能。
- 完成一个学生管理程序,使用学号作为键添加5个学生对象,并可以将全部信息保存在文件中,可以实现对学生信息的学号查找,输出全部学生信息的功能。
- 完成一个学生管理程序,使用学号作为键添加5个学生对象,并可以将全部信息保存在文件中,可以实现对学生信息的学号查找,输出全部学生信息的功能。
- 完成一个学生管理程序,使用学号作为键添加5个学生对象,并可以将全部信息保存在文件中,可以实现对学生信息的学号查找,输出全部学生信息的功能。
- 完成一个学生管理程序,使用学号作为键添加5个学生对象,并可以将全部信息保存在文件中,可以实现对学生信息的学号查找,输出全部学生信息的功能。
- 完成一个学生管理程序,使用学号作为键添加5个学生对象,并可以将全部信息保存在文件中,可以实现对学生信息的学号查找,输出全部学生信息的功能。
- 完成一个学生管理程序,使用学号作为键添加5个学生对象,并可以将全部信息保存在文件中,可以实现对学生信息的学号查找,输出全部学生信息的功能。
- 一个WinForm程序配置信息的简单模型和维护工具——使用说明
- [转]如何使用国际开源项目构建一个完整的GIS(地理信息)应用系统
- 使用easyui 做后台管理界面,在Tab中的链接点击后添加一个新TAB的解决方法
- iPhone开发学习笔记005——使用XIB自定义一个UIView,然后将这个view添加到controller的view
- 使用dom模型为xml添加信息
- 使用zend framework 搭建网站(六)--为Zend_Session 添加一个Memcache_ SaveHandler