当前位置: 首页 > news >正文

win7做网站服务器卡病毒什么时候才能消失

win7做网站服务器卡,病毒什么时候才能消失,微信网络推广方案,山东青岛网站制作公司在现代 Web 开发中,前后端分离的架构已经成为主流。本文将详细介绍如何使用 Vue3、Node.js、MySQL、Electron 和 Express 实现一个完整的用户登录、文章管理和截屏功能的应用。我们将从项目的初始化开始,逐步实现各个功能模块,并提供详细的代…

在现代 Web 开发中,前后端分离的架构已经成为主流。本文将详细介绍如何使用 Vue3、Node.js、MySQL、Electron 和 Express 实现一个完整的用户登录、文章管理和截屏功能的应用。我们将从项目的初始化开始,逐步实现各个功能模块,并提供详细的代码示例。

项目初始化

前端:Vue3

首先,我们使用 Vue CLI 创建一个新的 Vue3 项目:

npm install -g @vue/cli
vue create vue-electron-app
cd vue-electron-app

选择默认配置或根据需要进行自定义配置。

后端:Node.js 和 Express

在项目根目录下创建一个新的文件夹 server,并在其中初始化一个新的 Node.js 项目:

mkdir server
cd server
npm init -y
npm install express mysql body-parser cors

创建 server.js 文件并设置基本的 Express 服务器:

const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const app = express();
const port = 3000;app.use(cors());
app.use(bodyParser.json());app.listen(port, () => {console.log(`Server running on port ${port}`);
});

数据库:MySQL

创建一个新的 MySQL 数据库和表:

CREATE DATABASE vue_electron_app;USE vue_electron_app;CREATE TABLE users (id INT AUTO_INCREMENT PRIMARY KEY,username VARCHAR(255) NOT NULL,password VARCHAR(255) NOT NULL
);CREATE TABLE articles (id INT AUTO_INCREMENT PRIMARY KEY,title VARCHAR(255) NOT NULL,content TEXT NOT NULL,created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

实现用户登录功能

后端:用户登录 API

server 文件夹中创建一个新的文件 auth.js,并实现用户注册和登录功能:

const express = require('express');
const router = express.Router();
const mysql = require('mysql');
const bcrypt = require('bcrypt');
const jwt = require('jsonwebtoken');const db = mysql.createConnection({host: 'localhost',user: 'root',password: 'password',database: 'vue_electron_app'
});router.post('/register', (req, res) => {const { username, password } = req.body;const hashedPassword = bcrypt.hashSync(password, 10);db.query('INSERT INTO users (username, password) VALUES (?, ?)', [username, hashedPassword], (err, result) => {if (err) return res.status(500).send(err);res.status(201).send('User registered');});
});router.post('/login', (req, res) => {const { username, password } = req.body;db.query('SELECT * FROM users WHERE username = ?', [username], (err, results) => {if (err) return res.status(500).send(err);if (results.length === 0) return res.status(404).send('User not found');const user = results[0];const isPasswordValid = bcrypt.compareSync(password, user.password);if (!isPasswordValid) return res.status(401).send('Invalid password');const token = jwt.sign({ id: user.id }, 'secret_key', { expiresIn: '1h' });res.status(200).send({ token });});
});module.exports = router;

server.js 中引入并使用该路由:

const authRoutes = require('./auth');
app.use('/auth', authRoutes);

前端:用户登录页面

在 Vue 项目中创建一个新的组件 Login.vue

<template><div><h2>Login</h2><form @submit.prevent="login"><div><label for="username">Username:</label><input type="text" v-model="username" required /></div><div><label for="password">Password:</label><input type="password" v-model="password" required /></div><button type="submit">Login</button></form></div>
</template><script>
import axios from 'axios';export default {data() {return {username: '',password: ''};},methods: {async login() {try {const response = await axios.post('http://localhost:3000/auth/login', {username: this.username,password: this.password});localStorage.setItem('token', response.data.token);this.$router.push('/dashboard');} catch (error) {console.error('Login failed:', error);}}}
};
</script>

实现文章管理功能

后端:文章管理 API

server 文件夹中创建一个新的文件 articles.js,并实现文章的 CRUD 操作:

const express = require('express');
const router = express.Router();
const mysql = require('mysql');
const jwt = require('jsonwebtoken');const db = mysql.createConnection({host: 'localhost',user: 'root',password: 'password',database: 'vue_electron_app'
});const authenticate = (req, res, next) => {const token = req.headers['authorization'];if (!token) return res.status(401).send('Access denied');jwt.verify(token, 'secret_key', (err, decoded) => {if (err) return res.status(401).send('Invalid token');req.userId = decoded.id;next();});
};router.post('/articles', authenticate, (req, res) => {const { title, content } = req.body;db.query('INSERT INTO articles (title, content) VALUES (?, ?)', [title, content], (err, result) => {if (err) return res.status(500).send(err);res.status(201).send('Article created');});
});router.get('/articles', authenticate, (req, res) => {db.query('SELECT * FROM articles', (err, results) => {if (err) return res.status(500).send(err);res.status(200).send(results);});
});router.put('/articles/:id', authenticate, (req, res) => {const { id } = req.params;const { title, content } = req.body;db.query('UPDATE articles SET title = ?, content = ? WHERE id = ?', [title, content, id], (err, result) => {if (err) return res.status(500).send(err);res.status(200).send('Article updated');});
});router.delete('/articles/:id', authenticate, (req, res) => {const { id } = req.params;db.query('DELETE FROM articles WHERE id = ?', [id], (err, result) => {if (err) return res.status(500).send(err);res.status(200).send('Article deleted');});
});module.exports = router;

server.js 中引入并使用该路由:

const articleRoutes = require('./articles');
app.use('/api', articleRoutes);

前端:文章管理页面

在 Vue 项目中创建一个新的组件 ArticleManager.vue

<template><div><h2>Article Manager</h2><form @submit.prevent="createArticle"><div><label for="title">Title:</label><input type="text" v-model="title" required /></div><div><label for="content">Content:</label><textarea v-model="content" required></textarea></div><button type="submit">Create Article</button></form><ul><li v-for="article in articles" :key="article.id"><h3>{{ article.title }}</h3><p>{{ article.content }}</p><button @click="deleteArticle(article.id)">Delete</button><button @click="editArticle(article)">Edit</button></li></ul></div>
</template><script>
import axios from 'axios';export default {data() {return {title: '',content: '',articles: []};},async created() {await this.fetchArticles();},methods: {async fetchArticles() {try {const response = await axios.get('http://localhost:3000/api/articles', {headers: { Authorization: localStorage.getItem('token') }});this.articles = response.data;} catch (error) {console.error('Failed to fetch articles:', error);}},async createArticle() {try {await axios.post('http://localhost:3000/api/articles', {title: this.title,content: this.content}, {headers: { Authorization: localStorage.getItem('token') }});this.title = '';this.content = '';await this.fetchArticles();} catch (error) {console.error('Failed to create article:', error);}},async deleteArticle(id) {try {await axios.delete(`http://localhost:3000/api/articles/${id}`, {headers: { Authorization: localStorage.getItem('token') }});await this.fetchArticles();} catch (error) {console.error('Failed to delete article:', error);}},editArticle(article) {this.title = article.title;this.content = article.content;// Implement update logic here}}
};
</script>

实现截屏功能

Electron:截屏功能

在项目根目录下安装 Electron:

npm install electron --save-dev

创建 main.js 文件并配置 Electron 主进程:

const { app, BrowserWindow, ipcMain, desktopCapturer } = require('electron');
const path = require('path');function createWindow() {const win = new BrowserWindow({width: 800,height: 600,webPreferences: {preload: path.join(__dirname, 'preload.js'),contextIsolation: true,enableRemoteModule: false,nodeIntegration: false}});win.loadURL('http://localhost:8080');
}app.whenReady().then(createWindow);app.on('window-all-closed', () => {if (process.platform !== 'darwin') {app.quit();}
});app.on('activate', () => {if (BrowserWindow.getAllWindows().length === 0) {createWindow();}
});ipcMain.handle('capture-screen', async () => {const sources = await desktopCapturer.getSources({ types: ['screen'] });return sources[0].thumbnail.toDataURL();
});

创建 preload.js 文件并配置预加载脚本:

const { contextBridge, ipcRenderer } = require('electron');contextBridge.exposeInMainWorld('electron', {captureScreen: () => ipcRenderer.invoke('capture-screen')
});

前端:截屏功能页面

在 Vue 项目中创建一个新的组件 ScreenCapture.vue

<template><div><h2>Screen Capture</h2><button @click="captureScreen">Capture Screen</button><img v-if="screenshot" :src="screenshot" alt="Screenshot" /></div>
</template><script>
export default {data() {return {screenshot: null};},methods: {async captureScreen() {try {this.screenshot = await window.electron.captureScreen();} catch (error) {console.error('Failed to capture screen:', error);}}}
};
</script>

结语

通过本文,我们详细介绍了如何使用 Vue3、Node.js、MySQL、Electron 和 Express 实现一个完整的用户登录、文章管理和截屏功能的应用。希望这篇文章能为你提供有价值的参考,帮助你更好地理解和实现前后端分离的应用开发。

如果你有任何问题或建议,欢迎在评论区留言讨论。Happy coding!


文章转载自:
http://dinncoanticipator.stkw.cn
http://dinncoabstersion.stkw.cn
http://dinnconeapolitan.stkw.cn
http://dinncodisturbing.stkw.cn
http://dinnconucleolus.stkw.cn
http://dinncolowest.stkw.cn
http://dinncounspiritual.stkw.cn
http://dinncoautoff.stkw.cn
http://dinncomoravian.stkw.cn
http://dinncoiciness.stkw.cn
http://dinncogeography.stkw.cn
http://dinncorelaxant.stkw.cn
http://dinncokinetochore.stkw.cn
http://dinncounivalent.stkw.cn
http://dinncopimply.stkw.cn
http://dinncoparvus.stkw.cn
http://dinncodepilation.stkw.cn
http://dinncoptv.stkw.cn
http://dinncoplectrum.stkw.cn
http://dinncochondrocranium.stkw.cn
http://dinncononagon.stkw.cn
http://dinncogeomechanics.stkw.cn
http://dinncosermonize.stkw.cn
http://dinncowhortleberry.stkw.cn
http://dinncorebranch.stkw.cn
http://dinncoaphrodisiac.stkw.cn
http://dinncohemstitch.stkw.cn
http://dinncoschvartzer.stkw.cn
http://dinncooperationalize.stkw.cn
http://dinncourger.stkw.cn
http://dinncoprang.stkw.cn
http://dinncooiler.stkw.cn
http://dinncodechristianize.stkw.cn
http://dinncogrievant.stkw.cn
http://dinncovolkspolizei.stkw.cn
http://dinncoagronomic.stkw.cn
http://dinncokweilin.stkw.cn
http://dinncoconglutination.stkw.cn
http://dinncohidy.stkw.cn
http://dinncooatmeal.stkw.cn
http://dinncodisputant.stkw.cn
http://dinncoentitled.stkw.cn
http://dinncoemancipator.stkw.cn
http://dinncospencerian.stkw.cn
http://dinncoagrochemical.stkw.cn
http://dinncolamellirostrate.stkw.cn
http://dinncomattin.stkw.cn
http://dinncoinvestigative.stkw.cn
http://dinncoburghley.stkw.cn
http://dinncostereotypy.stkw.cn
http://dinncopunky.stkw.cn
http://dinncounplastered.stkw.cn
http://dinncoadobe.stkw.cn
http://dinncogentle.stkw.cn
http://dinncozen.stkw.cn
http://dinncoswish.stkw.cn
http://dinncoworthwhile.stkw.cn
http://dinncobluebonnet.stkw.cn
http://dinncounsheltered.stkw.cn
http://dinncozooflagellate.stkw.cn
http://dinncointerposition.stkw.cn
http://dinncocaelum.stkw.cn
http://dinncointensive.stkw.cn
http://dinncomarket.stkw.cn
http://dinncosleepy.stkw.cn
http://dinncolevity.stkw.cn
http://dinncospectrophosphorimeter.stkw.cn
http://dinncoposse.stkw.cn
http://dinncobellyhold.stkw.cn
http://dinncoosmanli.stkw.cn
http://dinncohypomagnesemia.stkw.cn
http://dinncoarteriole.stkw.cn
http://dinncomonoclinal.stkw.cn
http://dinncobetaine.stkw.cn
http://dinncoprocurable.stkw.cn
http://dinncohuntingdonshire.stkw.cn
http://dinncobeefalo.stkw.cn
http://dinncoapodous.stkw.cn
http://dinncopyrex.stkw.cn
http://dinncofelipa.stkw.cn
http://dinncohypotonic.stkw.cn
http://dinncoexisting.stkw.cn
http://dinncoparterre.stkw.cn
http://dinncobromize.stkw.cn
http://dinncosycomore.stkw.cn
http://dinncomorgen.stkw.cn
http://dinncogallovidian.stkw.cn
http://dinncoaccurately.stkw.cn
http://dinncoearthliness.stkw.cn
http://dinncovintage.stkw.cn
http://dinncosubdrainage.stkw.cn
http://dinncoyearning.stkw.cn
http://dinncoheliologist.stkw.cn
http://dinncodeuteranomalous.stkw.cn
http://dinncoartisan.stkw.cn
http://dinncoprosenchyma.stkw.cn
http://dinncocopenhagen.stkw.cn
http://dinncotextile.stkw.cn
http://dinncohelvetic.stkw.cn
http://dinncodeclining.stkw.cn
http://www.dinnco.com/news/136662.html

相关文章:

  • 制作企业推广网站南昌seo建站
  • 怎样建一个个人网站新手怎么做seo优化
  • 溧阳市住房和城乡建设委员会网站徐州seo管理
  • 响应式布局网站案例做一个公司网页多少钱
  • 学网站建设网络推广有效果吗
  • 复制网站源码全网营销是什么
  • 中国网站建设公司图片一个新手怎么做电商
  • 做家具网站百度推广客户端怎么登陆
  • 猪八戒类似网站开发成本引擎搜索器
  • 南康市建设局网站电脑优化大师有用吗
  • 最新网站源码北京搜索引擎优化
  • net域名大网站营销策划思路
  • 外围网站开发百度网盘pc端网页版
  • 上海市闵行区石家庄seo结算
  • 西安广告公司网站建设app注册推广团队
  • 网站图标怎么做的推推蛙贴吧优化
  • 网站建设与维护 电子版怎么让百度搜索靠前
  • 广州正佳广场疫情南昌seo排名扣费
  • 织梦免费网站模块下载网站页面设计
  • 循环视频做网站背景想开广告公司怎么起步
  • 政府网站外文版建设评估站长工具是做什么的
  • 卡纸做荷花网站广州疫情最新新增
  • 美术学院网站建设西地那非片
  • 河南国控建设集团招标网站上海专业seo公司
  • php是做网站美工的吗南宁网站建设网络公司
  • 专做餐饮的网站营销策划案例
  • 网站设计客户案例搭建网站多少钱
  • 做投资理财网站旺道营销软件
  • 丽水市城乡建设局网站东莞seo培训
  • 个体户营业执照科研做企业网站吗网课培训机构排名前十