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

目录

  • 引言
    • 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.mzph.cn/news/87042.shtml

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

相关文章

C语言每日一题(8):有序序列合并

文章主题&#xff1a;有序序列合并&#x1f525;&#x1f525;&#x1f525;所属专栏&#xff1a;C语言每日一题&#x1f4d7;作者简介&#xff1a;每天不定时更新C语言的小白一枚&#xff0c;记录分享自己每天的所思所想&#x1f604;&#x1f3b6;个人主页&#xff1a;[₽]的…

Linux的socket通信

关于套接字通信定义如下&#xff1a; 套接字对应程序猿来说就是一套网络通信的接口&#xff0c;使用这套接口就可以完成网络通信。网络通信的主体主要分为两部分&#xff1a;客户端和服务器端。在客户端和服务器通信的时候需要频繁提到三个概念&#xff1a;IP、端口、通信数据&…

排序:希尔排序(Shell Sort)算法分析

1.算法思想 希尔排序:先追求表中元素部分有序再逐渐逼近全局有序. 希尔排序∶先将待排序表分割成若干形如 L [ i , i d , i 2 d . . . . , i k d ] L[i,i d,i 2d ...., i kd] L[i,id,i2d....,ikd]的“特殊”子表&#xff0c; 对各个子表分别进行直接插入排序。缩小增量…

MySQL单表查询和多表查询

一、单表查询 素材&#xff1a; 表名&#xff1a;worker-- 表中字段均为中文&#xff0c;比如 部门号 工资 职工号 参加工作等 CREATE TABLE worker (部门号 int(11) NOT NULL,职工号 int(11) NOT NULL,工作时间 date NOT NULL,工资 float(8,2) NOT NULL,政治面貌 varchar(10)…

恒合仓库 - 采购单管理模块

采购单管理模块 文章目录 采购单管理模块一、添加采购单(核心)1.1 采购流程1.2 采购单实体类1.3 添加采购单1.3.1 Mapper1.3.2 Service1.3.3 Controller1.3.4 效果图 二、采购单管理模块2.1 仓库数据回显2.1.1 Mapper2.1.2 Service2.1.3 Controller2.1.4 效果图 2.2 采购单列表…

【Unity的HDRP渲染管线搭建配置VR交互场景_SteamVR 插件和Pico串流助手】

HDRP渲染管线配置VR交互场景 Unity创建场景和相关配置下载导入项目打开PICO串流助手在Pico中的配置:用Steam串流VR_这篇的前置补充 Unity创建场景和相关配置 带HDRP Sample Scene 示例的 下载 SteamVR Unity插件地址02 导入项目

怒刷LeetCode的第10天(Java版)

目录 第一题 题目来源 题目内容 解决方法 方法一&#xff1a;两次拓扑排序 第二题 题目来源 题目内容 解决方法 方法一&#xff1a;分治法 方法二&#xff1a;优先队列&#xff08;Priority Queue&#xff09; 方法三&#xff1a;迭代 第三题 题目来源 题目内容…

【Vue】ElementUI实现登录注册

目录 一.跨域的概述 1.1.概述 1.2.特点 二.ElementUI 2.1. 导入 2.2.搭建 2.3.页面 三.数据交互 3.1.安装相关模块 3.1.1安装模块 3.1.2查看模块 3.1.3.引用模块 3.2. axios的get请求 3.3. axios的post请求 四.注册功能 好啦今天到这了&#xff0c;希望能帮到你&…

Matplotlib 是一个广泛用于 Python 数据可视化的库

Matplotlib 是一个广泛用于 Python 数据可视化的库&#xff0c;它提供了丰富的绘图功能&#xff0c;允许用户创建各种类型的图表&#xff0c;从简单的折线图到复杂的三维图表&#xff0c;以及定制图形的各个方面。以下是Matplotlib的一些重要特点和常见用法&#xff1a; Matpl…

向量数据库库Milvus Cloud2.3 技术选型中性能、成本、扩展性是重点

技术选型中性能、成本、扩展性是重点 对于向量数据库来说,用户最关心的莫过于性能、成本和扩展性。 Milvus 2.x 从 Day 1 开始就将扩展性作为设计的第一优先级,在众多用户环境中落地了十亿至百亿级别场景。不止如此,对于 Milvus 来说,扩展性不仅仅意味着支持百亿级别向量,…

网站整站优化-网站整站优化工具

您是否曾为您的网站在搜索引擎中的排名而感到焦虑&#xff1f;是否苦苦思考如何提高流量、吸引更多用户&#xff1f; 什么是整站优化。简而言之&#xff0c;它是一项用于提升网站在搜索引擎中排名的策略和技巧。通过对网站的内容、结构、速度等方面进行优化&#xff0c;可以使…

wordpress使用category order and taxonomy terms order插件实现分类目录的拖拽排序

文章目录 引入实现效果安装插件使用插件 引入 使用docker快速搭建wordpress服务&#xff0c;并指定域名访问 上一节我们使用docker快速搭建了wordpress服务&#xff0c;可以看到基础的wordpress服务已经集成基础的用户管理、文章发布、页面编辑、文章分类等功能&#xff0c;但…

当下IT测试技术员的求职困境

从去年被裁到现在&#xff0c;自由职业的我已经有一年没有按部就班打卡上班了。期间也面试了一些岗位&#xff0c;有首轮就挂的&#xff0c;也有顺利到谈薪阶段最后拿了offer的&#xff0c;不过最后选择了拒绝。 基于自己近一年的面试求职经历&#xff0c;我想聊聊当下大家在求…

时序数据库 IoTDB 发布端边云原生解决方案,有效优化工业互联网数据上传时效与资源消耗...

2023 年 9 月 8 日&#xff0c;由中国通信学会、福建省工业和信息化厅主办的 2023 中国国际工业互联网创新发展大会在厦门举办。大会主论坛中&#xff0c;时序数据库 IoTDB 发表其自研建立的端边云原生解决方案&#xff0c;该方案可实现端侧设备、边缘服务器、数据中心数据的协…

安卓备份基带分区 备份字库 步骤解析 以免误檫除分区或者“格机” 后悔莫及

玩机搞机---安卓机型mtk和高通芯片查看分区 导出分区 备份分区的一些工具分析 修复基带 改串码 基带qcn 改相关参数 格机危害 手机基带的重要性前面几期博文我都有相关的说明。他区别于别的分区。而且目前手机的安全性越来越高。基带分区基本都是专机专用。而不像早期机型一…

代码随想录Day02 数组基础2 leetcode T977有序数组的平方, T209 长度最小的子数组,T59 螺旋矩阵II

本文思路和详细解答来源于: 代码随想录 视频讲解见: 双指针法经典题目 | LeetCode&#xff1a;977.有序数组的平方_哔哩哔哩_bilibili Leetcode T977 有序数组的平方 题目链接: 977. 有序数组的平方 - 力扣&#xff08;LeetCode&#xff09; 思路1: 暴力求解 这里先解释一下非…

图像相关名词概述

颜色模式 通过赋予C的不同维度不同的含义&#xff0c;可以用来描述不同的颜色空间。颜色模式&#xff0c;是将某种颜色表现为数字形式的模型&#xff0c;或者说是一种记录图像颜色的方式。本单元主要讲述两个常用的颜色模式&#xff1a;RGB&#xff0c;HSV。 RGB模式是工业界的…

为什么atomic不是线程安全的

原理 1、读取i的值存入寄存器&#xff1b; 2、将i加1&#xff1b; 3、修改i的值&#xff1b; 修改一个属性包含了读&#xff0c;执行 改变&#xff0c;写入&#xff0c;atomic 只为读和写加了锁&#xff0c;保证了同一个时间只有一个线程在读和写&#xff0c;但是&#xff0c;会…

开关电源-交流220V降压电路-电阻电容降压原理

阻容降压原理 电容电阻降压的原理其实比较简单。它的工作原理是电容在交流信号的情况下&#xff0c;产生容抗来限制最大的工作电流。说白了就是电容使用它自己的通交流阻直流的性能&#xff0c;在交流信号输入时电容产生容抗。我们通过他的这个特性&#xff0c;可以设计出&…

2614. 对角线上的质数-c语言解法

给你一个下标从 0 开始的二维整数数组 nums 。 返回位于 nums 至少一条 对角线 上的最大 质数 。如果任一对角线上均不存在质数&#xff0c;返回 0 。 注意&#xff1a; 如果某个整数大于 1 &#xff0c;且不存在除 1 和自身之外的正整数因子&#xff0c;则认为该整数是一个…