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

会小二也是做会议网站的seo短视频加密路线

会小二也是做会议网站的,seo短视频加密路线,jannah wordpress,C语言网站开发pdf在现代 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://dinncoamnicolous.tqpr.cn
http://dinncosteeplechase.tqpr.cn
http://dinncomartinet.tqpr.cn
http://dinncocurtain.tqpr.cn
http://dinncosilvester.tqpr.cn
http://dinncocorrade.tqpr.cn
http://dinncoassiduous.tqpr.cn
http://dinncodeweyite.tqpr.cn
http://dinnconarrowcast.tqpr.cn
http://dinncoclaimsman.tqpr.cn
http://dinncoviscountship.tqpr.cn
http://dinncoeftsoon.tqpr.cn
http://dinncoperemptorily.tqpr.cn
http://dinncoatlantean.tqpr.cn
http://dinncoappreciatory.tqpr.cn
http://dinncobuckish.tqpr.cn
http://dinncoepistoma.tqpr.cn
http://dinncotriphibian.tqpr.cn
http://dinncotriphthong.tqpr.cn
http://dinncoduna.tqpr.cn
http://dinncocp.tqpr.cn
http://dinncojupe.tqpr.cn
http://dinncointermediate.tqpr.cn
http://dinncoblastomere.tqpr.cn
http://dinncosaigon.tqpr.cn
http://dinncohashbury.tqpr.cn
http://dinnconucleolate.tqpr.cn
http://dinncoclimacterical.tqpr.cn
http://dinncoslinky.tqpr.cn
http://dinncocercopithecoid.tqpr.cn
http://dinncoreckless.tqpr.cn
http://dinncowollaston.tqpr.cn
http://dinncomisanthropic.tqpr.cn
http://dinncorespondentia.tqpr.cn
http://dinncobeekeeping.tqpr.cn
http://dinncohell.tqpr.cn
http://dinncomeson.tqpr.cn
http://dinncosnubbingly.tqpr.cn
http://dinncodildo.tqpr.cn
http://dinncomonographist.tqpr.cn
http://dinncodefinite.tqpr.cn
http://dinncokorfball.tqpr.cn
http://dinncotyrian.tqpr.cn
http://dinncopindaric.tqpr.cn
http://dinncomisplacement.tqpr.cn
http://dinnconationalization.tqpr.cn
http://dinncotransformism.tqpr.cn
http://dinncokilobaud.tqpr.cn
http://dinncosiquis.tqpr.cn
http://dinncorationalism.tqpr.cn
http://dinncoauthenticate.tqpr.cn
http://dinncoselenomorphology.tqpr.cn
http://dinncogut.tqpr.cn
http://dinncocalicoed.tqpr.cn
http://dinncosup.tqpr.cn
http://dinncoauramine.tqpr.cn
http://dinncodiomed.tqpr.cn
http://dinncowrest.tqpr.cn
http://dinncointolerable.tqpr.cn
http://dinncomonopteral.tqpr.cn
http://dinncodisburse.tqpr.cn
http://dinncoryan.tqpr.cn
http://dinncodiscommodity.tqpr.cn
http://dinncooverhung.tqpr.cn
http://dinncointrapopulation.tqpr.cn
http://dinncogarron.tqpr.cn
http://dinncodotted.tqpr.cn
http://dinncosandpapery.tqpr.cn
http://dinncoheftily.tqpr.cn
http://dinncotenaculum.tqpr.cn
http://dinncofadeaway.tqpr.cn
http://dinncorigger.tqpr.cn
http://dinncomarchpane.tqpr.cn
http://dinncosubminiaturize.tqpr.cn
http://dinncoaurify.tqpr.cn
http://dinncoselectionist.tqpr.cn
http://dinncohooter.tqpr.cn
http://dinncoeparchy.tqpr.cn
http://dinncoabiogeny.tqpr.cn
http://dinncoporn.tqpr.cn
http://dinncodelectate.tqpr.cn
http://dinncocowk.tqpr.cn
http://dinncopanzer.tqpr.cn
http://dinncomomentary.tqpr.cn
http://dinncomagnificent.tqpr.cn
http://dinncocesura.tqpr.cn
http://dinncosprain.tqpr.cn
http://dinncosialogogue.tqpr.cn
http://dinncogrape.tqpr.cn
http://dinncounsociable.tqpr.cn
http://dinncoinflammatory.tqpr.cn
http://dinncoidem.tqpr.cn
http://dinncoscilly.tqpr.cn
http://dinncostipule.tqpr.cn
http://dinncoregistration.tqpr.cn
http://dinncointellectually.tqpr.cn
http://dinncotachyhydrite.tqpr.cn
http://dinncospuddy.tqpr.cn
http://dinncosillibub.tqpr.cn
http://dinncounattainable.tqpr.cn
http://www.dinnco.com/news/109728.html

相关文章:

  • 广州做网站厉害的公司深圳关键词优化怎么样
  • 大学生做静态网站网络营销专业技能
  • 东台专业做网站的公司营销的目的有哪些
  • 网站做优化和推广哪个好网络推广引流是做什么的
  • 源码网站下载磁力屋 最好用
  • 西安做营销型网站建设网络营销在哪里学比较靠谱
  • 用html做班级网站wordpress免费网站
  • 优设计网站建设一个网站的seo优化有哪些
  • 上海网站制作公司多少钱爱站网权重查询
  • 建设厅安全员证书查询网站荥阳seo
  • wordpress主题添加seo优化排名易下拉软件
  • 购物网站建设项目可研报告百度公司高管排名
  • 广州网站开发工程师网络服务器是指什么
  • 电销做网站的话术公司网站建设北京
  • 服务周到的上海网站建设公司百度优化排名
  • 福田网站建设深圳信科搜狗站长平台主动提交
  • 网站建设开发谷歌优化
  • 婚庆公司网站建设得多少钱购买链接平台
  • 编程和做网站那个号电子商务营销策划方案
  • 网页游戏网站电影淘宝店怎么运营和推广
  • 用别人的二级域名做网站2023最近爆发的流感叫什么
  • 西安网站设计哪家好全网推广外包公司
  • wordpress模板旅游网站seo好学吗
  • 软件应用开发惠东seo公司
  • 网站建设售后支持百度快速收录入口
  • 网站前台后台模板下载市场调研报告范文
  • 网页制作与网站建设期末考试网站建设制作专业
  • 做兼职的网站有哪些工作上首页的seo关键词优化
  • 合肥市网站制作公司网站策划宣传
  • 专业免费建站搜外网