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

微软网站开发惠州seo代理

微软网站开发,惠州seo代理,网站做外链推广的常用方法,adobe illustrator做网站fetch 基本使用跨域处理 fetch 基本使用 在node使用原生ajax发请求:XMLHttpRequest()1.获取xhr对象 2.注册回调函数 3.设置参数,请求头 4.发起连接原生ajax没有带异步处理 promise;原生ajax封装一下,以便重复调用jQuery&#…

  • fetch 基本使用
  • 跨域处理

fetch 基本使用

在node使用原生ajax发请求:XMLHttpRequest()1.获取xhr对象  2.注册回调函数  3.设置参数,请求头  4.发起连接原生ajax没有带异步处理 promise;原生ajax封装一下,以便重复调用jQuery:$ajax()Vue:axiosReact:fetch 已经封装好的ajax,并且带promise处理

src\utils\http.js(请求的封装)

/*http({url:"",method:"",params:{}  |  data:{}    --------get请求params,post请求data}).then(res=>{//在这里直接拿到数据,不想要两次.then才拿到})使用token的内容也封装进去
*/const BASE_URL = '/api'  //基础请求路径  http://172.16.235.16:8888/*封装分析:get请求数据拼接到urllet xxx={id:1,username:"admin",password:123}fetch("http://localhost:8888/login/getuser?id=1&username=admin&password=123")fetch("http://localhost:8888/login/getuser?"+函数())函数(xxx){//对xxx进行处理let result= id=1&username=admin&password=123return  result}
*/
const jsonChangeToUrl=(json)=>{let arr=[];for(let name in json){arr.push(name+"="+json[name]);  //[id=1,name=admin,pwd=123]}return arr.join("&");  //"id=1&name=admin&pwd=123"
}const http=({url,method='get',params={},data={}})=>{if(!url)return; //如果没有传递请求路径,就结束请求const token=sessionStorage.getItem("token") || ""; //发起请求之前先获取tokenlet options={method,headers:{token},// body:JSON.stringify(data)}if(method.toLowerCase()==='post'){options.body=JSON.stringify(data)}return fetch(BASE_URL+url+"?"+jsonChangeToUrl(params),options).then(response => {if(response.status === 401){ //token失效window.location.href="/login";  //浏览器url地址栏}else {return response.json();}})
}export default http;

src\pages\login\index.js (使用fetch发起请求)

import { Button,Form, Input,Radio,message } from 'antd';
import './index.scss'
import {useNavigate} from "react-router-dom";
import http from "../../utils/http"; //二次封装后的fetchconst Login = () => {const navigate = useNavigate();//点击登录时触发const onFinish = values => { //表单提交触发函数,value:表单输入框的值// console.log('Success:', values);  //{id:1,username:admin,type:管理员}//未封装过的fetch发的请求/*fetch("http://localhost:8888/login/getuser?username=201&password=201&type=管理员").then(resp => {console.log(resp)return resp.json()  //resp.json()是将返回的数据转为对象给我用;resp.text()返回的只是单纯的文本时可用}).then(data => {console.log(data)}).catch((err)=>{console.log("错误信息:"+err)})*///自己封装的fetchhttp({url:"/login/getuser",params:values}).then(res => {console.log(res)sessionStorage.setItem("token",res.token)sessionStorage.setItem("user",JSON.stringify(res.data[0]))sessionStorage.setItem("power",JSON.stringify(res.power))if(res.code === 200){message.success("登录成功") //提示气泡navigate("/home");}})};return (<div className={"loginBox"}><Formname="basic"labelCol={{ span: 5 }}wrapperCol={{ span: 16 }}initialValues={{  //初始值roleLgoin:"学生"  //绑在checkbox上的}}onFinish={onFinish}autoComplete="off"><Form.Itemlabel="用户名"name="username"rules={[{ required: true, message: '请输入您的用户名!' }]}><Input /></Form.Item><Form.Itemlabel="密码"name="password"rules={[{ required: true, message: '请输入您的密码名!' }]}><Input.Password /></Form.Item><Form.Item name="roleLgoin" label={null}><Radio.Groupname="radiogroup"options={[{ value: '学生', label: '学生' },{ value: '管理员', label: '管理员' }]}/></Form.Item><Form.Item label={null}><Button type="primary" htmlType="submit">Submit</Button></Form.Item></Form></div>)}export default Login;

跨域处理

1.react配置文件暴露弹出来:git add .git commit -m 'msg'npm run eject2.找到配置文件:webpackDevServer.config.js  //在103行的proxy属性,代理只在开发阶段有用,项目上线要删掉proxy:{'/api':{target: 'http://localhost:8888',changeOrigin: true,pathRewrite: {'^/api': ' '}}}

不建议直接暴露文件的不可逆操作,建议使用 craco (create-react-app config)在 React 脚手架的基础上进行 Webpack 配置。具体内容在Webpack\Vite栏中查看

http://www.dtcms.com/wzjs/505838.html

相关文章:

  • 株洲做网站优化网络营销推广服务
  • 西安优秀的集团门户网站建设公司b2b网站
  • 网站一般用什么服务器推客平台
  • 个人网站可以做音乐吗全国疫情最新报告
  • 和朋友合伙做网站调价智能关键词软件
  • 男女做那个真实视频网站百度问答平台入口
  • 微网站摇一摇seo怎么做排名
  • 沈阳网站app制作seo搜索
  • 深圳做网站980app广告联盟平台
  • 用c语言可以做网站吗全网营销系统是不是传销
  • 医疗网站建设机构在线培训app
  • 做网站需要办什么手续怎么创建一个网页
  • 石家庄模板建站行业解决方案推广网站都有哪些
  • 做网站订阅号重庆seo整站优化方案范文
  • 温江网站制作seo网站编辑是做什么的
  • 网站源码还可以做授权么网络培训心得体会
  • 学校网站的目的网站设计公司建设网站
  • 嘉峪关建设厅官方网站海口seo快速排名优化
  • 教学类网站怎么做正规seo多少钱
  • 南宁网站建设服务seo工具查询
  • 网站不做icp备案爱站工具包的模块有哪些
  • 萧山网站制作公司如何网络营销自己的产品
  • 帮人做彩票网站有事吗网络营销的策略包括
  • 映射做网站seo排名第一的企业
  • 自助式建网站知识搜索引擎
  • 做本地的分类信息网站如何进行网站推广?网站推广的基本手段有哪些
  • 海淀注册公司杭州seo靠谱
  • 榆中建设局网站seo也成搜索引擎优化
  • 广州建站服务商个人博客网站怎么做
  • 直销网站有没有适合在家做的手工活网站友情链接交易平台