“构建完善的用户认证与数据交互系统“

目录

  • 引言
    • 1.ElementUI完成登录注册
      • 1. 登录页面设计与实现
      • 2. 注册页面设计与实现
    • 2.axios之get请求
    • 3.axios之post请求
    • 4.跨域问题的解决方案
    • 5.总结

在这里插入图片描述

引言

在现代Web应用程序开发中,用户认证和数据交互是至关重要的功能。本文将介绍如何使用ElementUI、axios和解决跨域问题来构建一个完善的用户认证与数据交互系统。我们将分别探讨ElementUI完成登录注册、axios之get请求、axios之post请求以及跨域问题的解决方案。

1.ElementUI完成登录注册

在构建一个Web应用程序时,用户登录和注册是必不可少的功能。ElementUI是一个流行的Vue.js组件库,提供了丰富的UI组件和样式,使得开发者可以轻松地构建出漂亮且易用的登录和注册页面。本节将介绍如何使用ElementUI来完成登录和注册功能,并展示一些常用的验证和表单处理技巧。

1. 登录页面设计与实现

main.js

// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
// 新添加1
import ElementUI from 'element-ui'
// 新添加2,避免后期打包样式不同,要放在import App from './App';之前
import 'element-ui/lib/theme-chalk/index.css'
import App from './App'
import router from './router'
// 新添加3
Vue.use(ElementUI)
Vue.config.productionTip = false/* eslint-disable no-new */
import axios from '@/api/http'
import VueAxios from 'vue-axios'Vue.use(VueAxios,axios)
new Vue({el: '#app',router,components: { App },template: '<App/>'
})

// 新添加3
Vue.use(ElementUI)
Vue.config.productionTip = false

在app后面添加
重要的事情说三遍:在指定位置!!!在指定位置!!!在指定位置!!!~~~添加三行代码
配置路由

import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import Login from '@/views/Login'
import Register from '@/views/Register'
Vue.use(Router)export default new Router({routes: [{path: '/',name: 'Login',component: Login},{path: '/Register',name: 'Register',component: Register}]
})

登录界面

    <template><div class="login-wrap"><el-form class="login-container"><h1 class="title">用户登录</h1><el-form-item label=""><el-input type="text" v-model="username" placeholder="登录账号" autocomplete="off"></el-input></el-form-item><el-form-item label=""><el-input type="password" v-model="password" placeholder="登录密码" autocomplete="off"></el-input></el-form-item><el-form-item><el-button type="primary" style="width:100%;" @click="doSubmit()">提交</el-button></el-form-item><el-row style="text-align: center;margin-top:-10px"><el-link type="primary">忘记密码</el-link><el-link type="primary" @click="gotoRegister()">用户注册</el-link></el-row></el-form></div></template><script>// import axios from 'axios'// import qs from 'qs'export default {name: 'Login',data() {return {username: '',password: ''}},methods: {gotoRegister() {this.$router.push('/Register');},doSubmit() {let url = this.axios.urls.SYSTEM_USER_DOLOGIN;let params = {username: this.username,password: this.password}this.axios.post(url, params).then(r => {console.log(r)if (r.data.success) {this.$message({type: 'success',message: r.data.msg});this.$router.push('/Register');}else{console.log(r)this.$message(r.data.msg)}}).catch(e => {})}}}</script><style scoped>.login-wrap {box-sizing: border-box;width: 100%;height: 100%;padding-top: 10%;background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+Cjxzdmcgd2lkdGg9IjEzNjFweCIgaGVpZ2h0PSI2MDlweCIgdmlld0JveD0iMCAwIDEzNjEgNjA5IiB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPgogICAgPCEtLSBHZW5lcmF0b3I6IFNrZXRjaCA0Ni4yICg0NDQ5NikgLSBodHRwOi8vd3d3LmJvaGVtaWFuY29kaW5nLmNvbS9za2V0Y2ggLS0+CiAgICA8dGl0bGU+R3JvdXAgMjE8L3RpdGxlPgogICAgPGRlc2M+Q3JlYXRlZCB3aXRoIFNrZXRjaC48L2Rlc2M+CiAgICA8ZGVmcz48L2RlZnM+CiAgICA8ZyBpZD0iQW50LURlc2lnbi1Qcm8tMy4wIiBzdHJva2U9Im5vbmUiIHN0cm9rZS13aWR0aD0iMSIgZmlsbD0ibm9uZSIg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4yNSI+PC9jaXJjbGU+CiAgICAgICAgICAgICAgICAgICAgPGNpcmNsZSBpZD0iT3ZhbC01LUNvcHktMiIgZmlsbC1vcGFjaXR5PSIwLjYiIGZpbGw9IiNEMURFRUQiIGN4PSI4Ljc1IiBjeT0iMzMuMjUiIHI9IjguNzUiPjwvY2lyY2xlPgogICAgICAgICAgICAgICAgICAgIDxjaXJjbGUgaWQ9Ik92YWwtNS1Db3B5LTQiIGZpbGwtb3BhY2l0eT0iMC42IiBmaWxsPSIjRDFERUVEIiBjeD0iMjQzLjgzMzMzMyIgY3k9IjMwLjMzMzMzMzMiIHI9IjUuODMzMzMzMzMiPjwvY2lyY2xlPgogICAgICAgICAgICAgICAgICAgIDxjaXJjbGUgaWQ9Ik92YWwtNS1Db3B5LTUiIGZpbGw9IiNFMEI0QjciIGN4PSIxNzUuNTgzMzMzIiBjeT0iMjMyLjc1IiByPSI1LjI1Ij48L2NpcmNsZT4KICAgICAgICAgICAgICAgIDwvZz4KICAgICAgICAgICAgPC9nPgogICAgICAgIDwvZz4KICAgIDwvZz4KPC9zdmc+);/* background-color: #112346; */background-repeat: no-repeat;background-position: center right;background-size: 100%;}.login-container {border-radius: 10px;margin: 0px auto;width: 350px;padding: 30px 35px 15px 35px;background: #fff;border: 1px solid #eaeaea;text-align: left;box-shadow: 0 0 20px 2px rgba(0, 0, 0, 0.1);}.title {margin: 0px auto 40px auto;text-align: center;color: #505458;}</style>

App.vue样式

<style> 
html,
body {width: 100%;height: 100%;box-sizing: border-box;padding: 0px;margin: 0px;
}
#app {font-family: "Avenir", Helvetica, Arial, sans-serif;-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;color: #2c3e50;widows: 100%;height: 100%;
}
</style>

2. 注册页面设计与实现

注册页面与登录页面类似,也需要一个表单来接收用户输入的注册信息,并提供注册按钮来提交表单。在注册页面中,我们还可以使用ElementUI的其他组件,如下拉框、日期选择器等,来提供更多的注册选项。同样,我们也可以利用ElementUI的表单验证功能来确保用户输入的合法性。

<template><div class="register-container"><div class="register-card"><h2 class="register-title">注册</h2><form @submit.prevent="register" class="register-form"><div class="form-group"><label for="username" class="register-label">用户名:</label><input type="text" id="username" v-model="username" required class="register-input"></div><div class="form-group"><label for="password" class="register-label">密码:</label><input type="password" id="password" v-model="password" required class="register-input"></div><div class="form-group"><label for="password" class="register-label">编号:</label><input type="password" id="id" v-model="id" required class="register-input"></div><button type="submit" class="register-button">注册</button></form><div class="login-link"><span>已有账号?</span><el-link type="primary" @click="gotoLogin()">用户登录</el-link></div></div></div>
</template><style>
.register-container {display: flex;flex-direction: column;align-items: center;justify-content: center;height: 100vh;background-color: #f5f5f5;
}.register-card {display: flex;flex-direction: column;align-items: center;background-color: #fff;padding: 40px;border-radius: 4px;box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}.register-title {font-size: 24px;color: #333;margin-bottom: 20px;
}.register-form {display: flex;flex-direction: column;align-items: center;
}.form-group {margin-bottom: 20px;
}.register-label {font-size: 16px;color: #333;margin-bottom: 10px;
}.register-input {padding: 8px;border: 1px solid #ccc;border-radius: 4px;width: 200px;
}.register-button {padding: 10px 20px;background-color: #ff6700;color: #fff;border: none;border-radius: 4px;cursor: pointer;
}.login-link {margin-top: 20px;display: flex;align-items: center;
}.login-link span {color: #555;
}.login-button {margin-left: 5px;color: #007bff;text-decoration: none;
}
</style><script>
export default {data() {return {username: '',password: '',id:''};},methods: {register() {let url = this.axios.urls.SYSTEM_USER_DOREG;let params = {username: this.username,password: this.password,id:this.id}
console.log(url)this.axios.post(url, params).then(r => {console.log(r)if (r.data.success) {this.$message({type: 'success',message: r.data.msg});}else{console.log(r)this.$message(r.data.msg)}}).catch(e => {})},gotoLogin(){this.$router.push('/');}}
};
</script>

后台代码

package com.zking.ssm.controller;import com.zking.ssm.model.User;
import com.zking.ssm.service.IUserService;
import com.zking.ssm.util.JsonResponseBody;
import com.zking.ssm.util.PageBean;
import com.zking.ssm.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.zking.ssm.jwt.*;@Controller
@RequestMapping("/user")
public class UserController {@Autowiredprivate IUserService userService;@RequestMapping("/userLogin")@ResponseBodypublic JsonResponseBody<?> userLogin(UserVo userVo, HttpServletResponse response){if(userVo.getUsername().equals("admin")&&userVo.getPassword().equals("123")){//私有要求claim
//            Map<String,Object> json=new HashMap<String,Object>();
//            json.put("username", userVo.getUsername());//生成JWT,并设置到response响应头中
//            String jwt=JwtUtils.createJwt(json, JwtUtils.JWT_WEB_TTL);
//            response.setHeader(JwtUtils.JWT_HEADER_KEY, jwt);return new JsonResponseBody<>("用户登陆成功!",true,0,null);}else{return new JsonResponseBody<>("用户名或密码错误!",false,0,null);}}@RequestMapping("/userRegister")@ResponseBodypublic JsonResponseBody<?> Register(User user, HttpServletResponse response) {if (user.getUsername() != null && user.getPassword() != null && user != null) {int n = userService.insertSelective(user);if (n > 0) {return new JsonResponseBody<>("注册成功!", true, 0, null);}}return new JsonResponseBody<>("用户名或密码错误!", false, 0, null);}@RequestMapping("/queryUserPager")@ResponseBodypublic JsonResponseBody<List<Map<String,Object>>>queryUserPager(UserVo userVo, HttpServletRequest request){try {PageBean pageBean=new PageBean();pageBean.setRequest(request);List<Map<String, Object>> users = userService.queryUserPager(userVo, pageBean);return new JsonResponseBody<>("OK",true,pageBean.getTotal(),users);} catch (Exception e) {e.printStackTrace();return new JsonResponseBody<>("分页查询用户信息失败!",false,0,null);}}
}

2.axios之get请求

在现代Web应用程序中,与后端服务器进行数据交互是非常常见的需求。axios是一个基于Promise的HTTP客户端,可以在浏览器和Node.js中发送HTTP请求。本节将介绍如何使用axios发送GET请求,并展示一些常用的请求参数配置和响应处理技巧。

项目下输入下面代码回车下载
npm i axios -S

   doSubmit() {let url = "http://localhost:8080/user/userLogin"let params = {username: this.username,password: this.password}axios.get(url, {params: params}).then(r => {console.log(r)if (r.data.success) {this.$message({type: 'success',message: r.data.msg});this.$router.push('/Register');}else{console.log(r)this.$message(r.data.msg)}}).catch(e => {})}

3.axios之post请求

除了GET请求,POST请求也是常用的数据交互方式之一。POST请求通常用于向服务器提交数据,如用户注册、表单提交等。本节将介绍如何使用axios发送POST请求,并展示一些常用的请求参数配置和响应处理技巧。
项目下输入下面代码回车下载
npm install qs -S
npm i vue-axios -S

 doSubmit() {let url = this.axios.urls.SYSTEM_USER_DOLOGIN;let params = {username: this.username,password: this.password}this.axios.post(url, params).then(r => {console.log(r)if (r.data.success) {this.$message({type: 'success',message: r.data.msg});this.$router.push('/Register');}else{console.log(r)this.$message(r.data.msg)}}).catch(e => {})}

action.js

/*** 对后台请求的地址的封装,URL格式如下:* 模块名_实体名_操作*/
export default {'SERVER': 'http://localhost:8080', //服务器'SYSTEM_USER_DOLOGIN': '/user/userLogin', //登陆'SYSTEM_USER_DOREG': '/user/userRegister', //注册'getFullPath': k => { //获得请求的完整地址,用于mockjs测试时使用return this.SERVER + this[k];}
}

http.js

/*** 对后台请求的地址的封装,URL格式如下:* 模块名_实体名_操作*/
export default {'SERVER': 'http://localhost:8080', //服务器'SYSTEM_USER_DOLOGIN': '/user/userLogin', //登陆'SYSTEM_USER_DOREG': '/userAction.action', //注册'getFullPath': k => { //获得请求的完整地址,用于mockjs测试时使用return this.SERVER + this[k];}
}

4.跨域问题的解决方案

在前后端分离的开发模式中,前端代码通常运行在一个独立的域名或端口上,而后端API则运行在另一个域名或端口上。由于浏览器的同源策略限制,跨域请求会受到限制。本节将介绍一些常用的跨域解决方案,如JSONP、CORS等,并展示如何使用axios来处理跨域请求。

web.xml配置过滤器

 <!--CrosFilter跨域过滤器--><filter><filter-name>corsFilter</filter-name><filter-class>com.zking.ssm.util.CorsFilter2</filter-class></filter><filter-mapping><filter-name>corsFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping>

过滤器

package com.zking.ssm.util;import java.io.IOException;import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;/*** 配置tomcat允许跨域访问* * @author Administrator**/
public class CorsFilter2 implements Filter {@Overridepublic void init(FilterConfig filterConfig) throws ServletException {}@Overridepublic void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)throws IOException, ServletException {HttpServletResponse httpResponse = (HttpServletResponse) servletResponse;// Access-Control-Allow-Origin就是我们需要设置的域名// Access-Control-Allow-Headers跨域允许包含的头。// Access-Control-Allow-Methods是允许的请求方式httpResponse.setHeader("Access-Control-Allow-Origin", "*");// *,任何域名httpResponse.setHeader("Access-Control-Allow-Headers", "responseType,Origin, X-Requested-With, Content-Type, Accept");httpResponse.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE");//允许客户端处理一个新的响应头jwt//httpResponse.setHeader("Access-Control-Expose-Headers", "jwt,Content-Disposition");filterChain.doFilter(servletRequest, servletResponse);}@Overridepublic void destroy() {}
}

5.总结

本文介绍了如何使用ElementUI、axios和解决跨域问题来构建一个完善的用户认证与数据交互系统。我们分别探讨了ElementUI完成登录注册、axios之get请求、axios之post请求以及跨域问题的解决方案。通过学习本文,您将掌握一些高级的前端技术实践,能够更好地应对现代Web应用程序开发中的挑战。希望本文对您有所帮助,谢谢阅读!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/140788.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【C++】STL详解(八)—— priority_queue的使用及模拟实现仿函数

​ ​&#x1f4dd;个人主页&#xff1a;Sherry的成长之路 &#x1f3e0;学习社区&#xff1a;Sherry的成长之路&#xff08;个人社区&#xff09; &#x1f4d6;专栏链接&#xff1a;C学习 &#x1f3af;长路漫漫浩浩&#xff0c;万事皆有期待 上一篇博客&#xff1a;【C】STL…

11.外观模式

外观模式&#xff08;Facade&#xff09;&#xff0c;为子系统中的一组接口提供一个一致的界面&#xff0c;此模式定义了一个高层接口&#xff0c;这个接口使得这一子系统更加容易使用。 UML 测试代码 #include <iostream> using namespace std;class SubSystemOne { pu…

Kafka 源码分析——Producer

文章目录 前言Producer 整体流程Producer 初始化Producer 发送流程执行拦截器逻辑获取集群元数据序列化选择分区消息累加进缓存消息发送 Producer缓冲区Producer 参数调优 前言 在 Kafka 中, 把产生消息的一方称为 Producer 即 生产者&#xff0c;它是 Kafka 的核心组件之一&a…

Spring面试题20:Spring怎样开启注解装配?

该文章专注于面试,面试只要回答关键点即可,不需要对框架有非常深入的回答,如果你想应付面试,是足够了,抓住关键点 面试官:Spring怎样开启注解装配? 要在Spring中开启注解装配,需要进行以下几个步骤: 添加必要的依赖:在项目的构建工具(如Maven或Gradle)配置文件中…

WebGL 选中一个表面

目录 选中一个表面 示例程序&#xff08;PickFace.js&#xff09; 代码详解 gl.readPixels()见126行效果 gl.UNSIGNED_BYTE注意点 示例效果 选中一个表面 ​​​​​​​WebGL 选中物体_山楂树の的博客-CSDN博客可以使用同样的方法来选中物体的某一个表面。这一节在Pi…

苹果手表 Series 6 拆解

步骤 1 苹果手表 Series 6 拆解 Series 6&#xff08;右&#xff09;与具有一年历史的姐妹&#xff08;左&#xff09;的外部比较仅显示出细微的差异&#xff0c;但这就是拆卸的目的。我们已经知道这些细节&#xff1a; LTPO OLED Retina 显示屏针对常亮功能进行了优化——这次…

亚马逊 CodeWhisperer 初体验

1、CodeWhisperer 介绍 CodeWhisperer 是亚马逊出品的一款基于机器学习的通用代码生成器&#xff0c;可实时提供代码建议。类似 Cursor 和 Github Copilot 编码工具。 官网&#xff1a;AI 代码生成器 - Amazon CodeWhisperer - AWS 在编写代码时&#xff0c;它会自动根据您现…

【深度学习实验】前馈神经网络(三):自定义两层前馈神经网络(激活函数logistic、线性层算子Linear)

目录 一、实验介绍 二、实验环境 1. 配置虚拟环境 2. 库版本介绍 三、实验内容 0. 导入必要的工具包 1. 构建数据集 2. 激活函数logistic 3. 线性层算子 Linear 4. 两层的前馈神经网络MLP 5. 模型训练 一、实验介绍 本实验实现了一个简单的两层前馈神经网络 激活函数…

JavaScript(WebAPI)

目录 一.WebAPI 二.DOM 1.选中页面元素 2.事件 三.操作元素 获取修改元素内容 获取/修改表单元素属性 value type 获取/修改样式属性 1.修改内联样式 2.修改元素应用的CSS类名 四.操作节点 1.新增元素 2.删除元素 五.小结 六.案例 1.网页版本的猜数字 2.表白…

Python | 为FastAPI后端服务添加API Key认证(分别基于路径传参和header两种方式且swagger文档友好支持)

文章目录 01 前言02 路径传参方式添加API Key2.1 完整代码2.2 请求示例2.3 swagger文档测试 03 请求头Header方式传入API Key&#xff08;推荐&#xff09;3.1 完整代码3.2 请求示例3.3 swagger文档测试 01 前言 FastAPI&#xff0c;如其名所示&#xff0c;是一个极为高效的框…

CSS3有哪些新特性

CSS3 引入了许多新特性&#xff0c;以增强样式设计和页面布局的能力&#xff0c;提供更多的视觉效果和交互性。以下是一些 CSS3 中的新特性&#xff1a; 圆角边框&#xff08;Border Radius&#xff09;&#xff1a;圆角的边框&#xff0c;而不是传统的方形边框。 <!DOCTY…

Java面试被问了几个简单的问题,却回答的不是很好

作者&#xff1a;逍遥Sean 简介&#xff1a;一个主修Java的Web网站\游戏服务器后端开发者 主页&#xff1a;https://blog.csdn.net/Ureliable 觉得博主文章不错的话&#xff0c;可以三连支持一下~ 如有需要我的支持&#xff0c;请私信或评论留言&#xff01; 前言 前几天参加了…

解决0-1背包问题(方案二):一维dp数组(滚动数组)

往期文章&#xff1a;解决0-1背包问题&#xff08;方案一&#xff09;:二维dp数组_呵呵哒(&#xffe3;▽&#xffe3;)"的博客-CSDN博客https://blog.csdn.net/weixin_41987016/article/details/133207350?spm1001.2014.3001.5501 >>探索一维dp数组和二维dp数组的…

深入学习 Redis Cluster - 基于 Docker、DockerCompose 搭建 Redis 集群,处理故障、扩容方案

目录 一、基于 Docker、DockerCompose 搭建 Redis 集群 1.1、前言 1.2、编写 shell 脚本 1.3、执行 shell 脚本&#xff0c;创建集群配置文件 1.4、编写 docker-compose.yml 文件 1.5、启动容器 1.6、构建集群 1.7、使用集群 1.8、如果集群中&#xff0c;有节点挂了&am…

【沐风老师】3DMAX翻转折叠动画插件FoldFx使用方法详解

3DMAX翻转折叠动画插件FoldFx使用方法详解 3DMAX翻转折叠动画插件FoldFx&#xff0c;是3dMax运动图形工具&#xff0c;用于创建多边形折叠动画。用户几乎有无限的可能性&#xff0c;因为动画的每个方面都是可控的。 【适用版本】 适用于3dMax版本&#xff1a;2010及更新版本&a…

让Pegasus天马座开发板实现超声波测距

在完成《让Pegasus天马座开发板用上OLED屏》后&#xff0c;我觉得可以把超声波测距功能也在Pegasus天马座开发板上实现。于是在箱子里找到了&#xff0c;Grove - Ultrasonic Ranger 这一超声波测传感器。 官方地址: https://wiki.seeedstudio.com/Grove-Ultrasonic_Ranger 超声…

OCR -- 文本检测

目标检测&#xff1a; 不仅要解决定位问题&#xff0c;还要解决目标分类问题&#xff0c;给定图像或者视频&#xff0c;找出目标的位置&#xff08;box&#xff09;&#xff0c;并给出目标的类别&#xff1b; 文本检测&#xff1a; 给定输入图像或者视频&#xff0c;找出文本的…

SpringBoot之响应处理

文章目录 前言一、返回值处理器ReturnValueHandler流程关于HttpMessageConverters的初始化ReturnValueHandler与MappingJackson2HttpMessageConverter关联 二、内容协商内容协商原理底层源码 三、自定义MessageConverter总结 前言 包括返回值处理器ReturnValueHandler、内容协…

【Vue.js】使用Element搭建登入注册界面axios中GET请求与POST请求跨域问题

一&#xff0c;ElementUI是什么&#xff1f; Element UI 是一个基于 Vue.js 的桌面端组件库&#xff0c;它提供了一套丰富的 UI 组件&#xff0c;用于构建用户界面。Element UI 的目标是提供简洁、易用、美观的组件&#xff0c;同时保持灵活性和可定制性 二&#xff0c;Element…

套接字socket编程的基础知识点

目录 前言&#xff08;必读&#xff09; 网络字节序 网络中的大小端问题 为什么网络字节序采用的是大端而不是小端&#xff1f; 网络字节序与主机字节序之间的转换 字符串IP和整数IP 整数IP存在的意义 字符串IP和整数IP相互转换的方式 inet_addr函数&#xff08;会自…