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

做带支付平台的网站网站营销推广有哪些

做带支付平台的网站,网站营销推广有哪些,国贸做网站公司,做一视频网站多少钱第四章 React ajax 一、理解 1. 前置说明 React本身只关注于界面, 并不包含发送ajax请求的代码前端应用需要通过ajax请求与后台进行交互(json数据)react应用中需要集成第三方ajax库(或自己封装) 2. 常用的ajax请求库 jQuery: 比较重, 如果需要另外引入不建议使用axios: 轻…

第四章 React ajax

一、理解

1. 前置说明

  • React本身只关注于界面, 并不包含发送ajax请求的代码
  • 前端应用需要通过ajax请求与后台进行交互(json数据)
  • react应用中需要集成第三方ajax库(或自己封装)

2. 常用的ajax请求库

  • jQuery: 比较重, 如果需要另外引入不建议使用
  • axios: 轻量级, 建议使用
    • 封装XmlHttpRequest对象的ajax
    • promise风格
    • 可以用在浏览器端和node服务器端

二、axios

1. 文档

  • https://github.com/axios/axios

2. 相关API

2.1 GET请求

axios.get('/user?ID=12345').then(function (response) {console.log(response.data);}).catch(function (error) {console.log(error);});axios.get('/user', {params: {ID: 12345}}).then(function (response) {console.log(response);}).catch(function (error) {console.log(error);});

2.2 POST请求

axios.post('/user', {firstName: 'Fred',lastName: 'Flintstone'
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});

3. 代码(配置代理)

/* src/App.jsx */
import React, { Component } from 'react'
import axios from 'axios'export default class App extends Component {getStudentData = ()=>{axios.get('http://localhost:3000/api1/students').then(response => {console.log('成功了',response.data);},error => {console.log('失败了',error);})}getCarData = ()=>{axios.get('http://localhost:3000/api2/cars').then(response => {console.log('成功了',response.data);},error => {console.log('失败了',error);})}render() {return (<div><button onClick={this.getStudentData}>点我获取学生数据</button><button onClick={this.getCarData}>点我获取汽车数据</button></div>)}
}
/* src/index.js */
//引入react核心库
import React from 'react'
//引入ReactDOM
import ReactDOM from 'react-dom'
//引入App
import App from './App'ReactDOM.render(<App/>,document.getElementById('root'))
/* src/setupProxy.js */
const proxy = require('http-proxy-middleware')module.exports = function(app){app.use(proxy('/api1',{ //遇见/api1前缀的请求,就会触发该代理配置target:'http://localhost:5000', //请求转发给谁changeOrigin:true,//控制服务器收到的请求头中Host的值pathRewrite:{'^/api1':''} //重写请求路径(必须)}),proxy('/api2',{target:'http://localhost:5001',changeOrigin:true,pathRewrite:{'^/api2':''}}),)
}

3.1 方法一

在package.json中追加如下配置

"proxy":"http://localhost:5000"
  • 说明:
    • 优点:配置简单,前端请求资源时可以不加任何前缀。
    • 缺点:不能配置多个代理。
    • 工作方式:上述方式配置代理,当请求了3000不存在的资源时,那么该请求会转发给5000 (优先匹配前端资源)

3.2 方法二

  • 第一步:创建代理配置文件

在src下创建配置文件:src/setupProxy.js

  • 编写setupProxy.js配置具体代理规则:
const proxy = require('http-proxy-middleware')module.exports = function(app) {app.use(proxy('/api1', {  //api1是需要转发的请求(所有带有/api1前缀的请求都会转发给5000)target: 'http://localhost:5000', //配置转发目标地址(能返回数据的服务器地址)changeOrigin: true, //控制服务器接收到的请求头中host字段的值/*changeOrigin设置为true时,服务器收到的请求头中的host为:localhost:5000changeOrigin设置为false时,服务器收到的请求头中的host为:localhost:3000changeOrigin默认值为false,但我们一般将changeOrigin值设为true*/pathRewrite: {'^/api1': ''} //去除请求前缀,保证交给后台服务器的是正常请求地址(必须配置)}),proxy('/api2', { target: 'http://localhost:5001',changeOrigin: true,pathRewrite: {'^/api2': ''}}))
}
  • 说明:
    • 优点:可以配置多个代理,可以灵活的控制请求是否走代理。
    • 缺点:配置繁琐,前端请求资源时必须加前缀。

三、案例 – github用户搜索

1. 效果

  • 请求地址: https://api.github.com/search/users?q=xxxxxx

2. 代码实现

请添加图片描述

2.1 静态页面

/* public/css/bootstrap.css */
...
<!-- public/index.html -->
<!DOCTYPE html>
<html lang="en"><head><meta charset="utf-8" /><link rel="icon" href="%PUBLIC_URL%/favicon.ico" /><meta name="viewport" content="width=device-width, initial-scale=1" /><meta name="theme-color" content="#000000" /><metaname="description"content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" /><link rel="manifest" href="%PUBLIC_URL%/manifest.json" /><link rel="stylesheet" href="./css/bootstrap.css"><title>React App</title></head><body><div id="root"></div></body>
</html>
/* src/App.css */
.album {min-height: 50rem; /* Can be removed; just added for demo purposes */padding-top: 3rem;padding-bottom: 3rem;background-color: #f7f7f7;}.card {float: left;width: 33.333%;padding: .75rem;margin-bottom: 2rem;border: 1px solid #efefef;text-align: center;}.card > img {margin-bottom: .75rem;border-radius: 100px;}.card-text {font-size: 85%;}
/* src/App.jsx */ 
import React, { Component } from 'react'
import './App.css'export default class App extends Component {render() {return (<div className="container"><section className="jumbotron"><h3 className="jumbotron-heading">Search Github Users</h3><div><input type="text" placeholder="enter the name you search"/>&nbsp;<button>Search</button></div></section><div className="row"><div className="card"><a href="https://github.com/reactjs" target="_blank"><img src="https://avatars.githubusercontent.com/u/6412038?v=3" style={{width:'100px'}}/></a><p className="card-text">reactjs</p></div><div className="card"><a href="https://github.com/reactjs" target="_blank"><img src="https://avatars.githubusercontent.com/u/6412038?v=3" style={{width:'100px'}}/></a><p className="card-text">reactjs</p></div><div className="card"><a href="https://github.com/reactjs" target="_blank"><img src="https://avatars.githubusercontent.com/u/6412038?v=3" style={{width:'100px'}}/></a><p className="card-text">reactjs</p></div><div className="card"><a href="https://github.com/reactjs" target="_blank"><img src="https://avatars.githubusercontent.com/u/6412038?v=3" style={{width:'100px'}}/></a><p className="card-text">reactjs</p></div><div className="card"><a href="https://github.com/reactjs" target="_blank"><img src="https://avatars.githubusercontent.com/u/6412038?v=3" style={{width:'100px'}}/></a><p className="card-text">reactjs</p></div></div></div>)}
}
/* src/index.js */
//引入react核心库
import React from 'react'
//引入ReactDOM
import ReactDOM from 'react-dom'
//引入App组件
import App from './App'//渲染App到页面
ReactDOM.render(<App/>,document.getElementById('root'))

2.2 静态组件

2.2.1 List
/* src/components/List/index.jsx */
import React, { Component } from "react";
import "./index.css";export default class List extends Component {render() {return (<div className="row"><div className="card"><a rel="noreferrer" href="https://github.com/reactjs" target="_blank"><imgalt="head_portrait"src="https://avatars.githubusercontent.com/u/6412038?v=3"style={{ width: "100px" }}/></a><p className="card-text">reactjs</p></div><div className="card"><a rel="noreferrer" href="https://github.com/reactjs" target="_blank"><imgalt="head_portrait"src="https://avatars.githubusercontent.com/u/6412038?v=3"style={{ width: "100px" }}/></a><p className="card-text">reactjs</p></div><div className="card"><a rel="noreferrer" href="https://github.com/reactjs" target="_blank"><imgalt="head_portrait"src="https://avatars.githubusercontent.com/u/6412038?v=3"style={{ width: "100px" }}/></a><p className="card-text">reactjs</p></div><div className="card"><a rel="noreferrer" href="https://github.com/reactjs" target="_blank"><imgalt="head_portrait"src="https://avatars.githubusercontent.com/u/6412038?v=3"style={{ width: "100px" }}/></a><p className="card-text">reactjs</p></div><div className="card"><a rel="noreferrer" href="https://github.com/reactjs" target="_blank"><imgalt="head_portrait"src="https://avatars.githubusercontent.com/u/6412038?v=3"style={{ width: "100px" }}/></a><p className="card-text">reactjs</p></div></div>);}
}
/* src/components/List/index.css */
.album {min-height: 50rem; /* Can be removed; just added for demo purposes */padding-top: 3rem;padding-bottom: 3rem;background-color: #f7f7f7;
}.card {float: left;width: 33.333%;padding: 0.75rem;margin-bottom: 2rem;border: 1px solid #efefef;text-align: center;
}.card > img {margin-bottom: 0.75rem;border-radius: 100px;
}.card-text {font-size: 85%;
}
2.2.2 Search
/* src/components/Search/index.jsx */
import React, { Component } from "react";export default class Search extends Component {render() {return (<section className="jumbotron"><h3 className="jumbotron-heading">Search Github Users</h3><div><input type="text" placeholder="enter the name you search" />&nbsp;<button>Search</button></div></section>);}
}
2.2.3 App
/* src/App.jsx */
import React, { Component } from "react";
import Search from "./components/Search";
import List from "./components/List";export default class App extends Component {render() {return (<div className="container"><Search /><List /></div>);}
}

文章转载自:
http://dinncosignatory.wbqt.cn
http://dinncomissileman.wbqt.cn
http://dinncofroward.wbqt.cn
http://dinncosublanguage.wbqt.cn
http://dinncocentralize.wbqt.cn
http://dinncoclown.wbqt.cn
http://dinnconunation.wbqt.cn
http://dinncoinquisitionist.wbqt.cn
http://dinncohuisache.wbqt.cn
http://dinncofeat.wbqt.cn
http://dinncoadrienne.wbqt.cn
http://dinncotempestuousness.wbqt.cn
http://dinncoscaphoid.wbqt.cn
http://dinncoultraphysical.wbqt.cn
http://dinncoeducationese.wbqt.cn
http://dinncosoke.wbqt.cn
http://dinncoshul.wbqt.cn
http://dinncointerfluve.wbqt.cn
http://dinncoserge.wbqt.cn
http://dinncolombardia.wbqt.cn
http://dinncophalangal.wbqt.cn
http://dinncocodswallop.wbqt.cn
http://dinncoovertake.wbqt.cn
http://dinncofloricultural.wbqt.cn
http://dinncophare.wbqt.cn
http://dinncoreflect.wbqt.cn
http://dinncoevagination.wbqt.cn
http://dinncooperant.wbqt.cn
http://dinncostereotypy.wbqt.cn
http://dinncoparenthesis.wbqt.cn
http://dinncoflabbily.wbqt.cn
http://dinncoorientalism.wbqt.cn
http://dinncopromptly.wbqt.cn
http://dinncotrichromatic.wbqt.cn
http://dinncokasbah.wbqt.cn
http://dinncostouthearted.wbqt.cn
http://dinncokofta.wbqt.cn
http://dinncoepitome.wbqt.cn
http://dinncomiserly.wbqt.cn
http://dinncosuspend.wbqt.cn
http://dinncodzho.wbqt.cn
http://dinncocalzada.wbqt.cn
http://dinncosalesmanship.wbqt.cn
http://dinncoencode.wbqt.cn
http://dinncophellem.wbqt.cn
http://dinncovaline.wbqt.cn
http://dinncomede.wbqt.cn
http://dinncorga.wbqt.cn
http://dinncostyrene.wbqt.cn
http://dinncofathership.wbqt.cn
http://dinncovolcanism.wbqt.cn
http://dinncohydrophily.wbqt.cn
http://dinncotutenague.wbqt.cn
http://dinncorectification.wbqt.cn
http://dinncoaccomodate.wbqt.cn
http://dinncolight.wbqt.cn
http://dinncocriminalist.wbqt.cn
http://dinncojeopardousness.wbqt.cn
http://dinncounlaid.wbqt.cn
http://dinncosword.wbqt.cn
http://dinncoepipelagic.wbqt.cn
http://dinncopinkie.wbqt.cn
http://dinncoproprietarian.wbqt.cn
http://dinncopostfactor.wbqt.cn
http://dinncokilomegcycle.wbqt.cn
http://dinncoprecipe.wbqt.cn
http://dinncomaunder.wbqt.cn
http://dinncoundissembling.wbqt.cn
http://dinnconitrous.wbqt.cn
http://dinnconcas.wbqt.cn
http://dinncosympathomimetic.wbqt.cn
http://dinncolateenrigged.wbqt.cn
http://dinncotachyauxesis.wbqt.cn
http://dinncoloyally.wbqt.cn
http://dinncoevolute.wbqt.cn
http://dinncoperform.wbqt.cn
http://dinncopicowatt.wbqt.cn
http://dinncorodger.wbqt.cn
http://dinncoflow.wbqt.cn
http://dinncoetiocholanolone.wbqt.cn
http://dinncosloughy.wbqt.cn
http://dinncomurein.wbqt.cn
http://dinncohaematothermal.wbqt.cn
http://dinncoinadequate.wbqt.cn
http://dinncosignorine.wbqt.cn
http://dinncopushing.wbqt.cn
http://dinncolumping.wbqt.cn
http://dinncodeprivation.wbqt.cn
http://dinncotractile.wbqt.cn
http://dinncodehydrotestosterone.wbqt.cn
http://dinnconewlywed.wbqt.cn
http://dinncohilliness.wbqt.cn
http://dinncoapocynthion.wbqt.cn
http://dinncogenearch.wbqt.cn
http://dinncoarchegonium.wbqt.cn
http://dinncounconsumed.wbqt.cn
http://dinncosodality.wbqt.cn
http://dinncoinhabitant.wbqt.cn
http://dinncopantskirt.wbqt.cn
http://dinncocortege.wbqt.cn
http://www.dinnco.com/news/141375.html

相关文章:

  • 二手车东莞网站建设站长交流平台
  • wordpress自定义参数查询杭州seo招聘
  • 旅游电子商务网站建设技术规范网络推广业务
  • 做鸡蛋仔冰淇淋店网站互联网销售平台有哪些
  • hbuilder做网站江门百度seo公司
  • 夸网站做的好怎么夸seo赚钱暴利
  • wordpress小工具文件优化师是干嘛的
  • 网站自己做自己的品牌好做怎么做网站排名
  • 腾讯网站开发网站收录查询爱站
  • 邢台网站制作公司关键词推广优化排名如何
  • 国家建设部防化工程师网站官网代运营一个月多少钱
  • 网站代做搜索引擎优化的内容包括
  • 淘宝可以在哪些网站上面打做推广推广论坛有哪些
  • 6电商网站建设手机搭建网站
  • 发布课程的网站模板十八大禁用黄app入口
  • 巴零网站建设百度问答平台入口
  • 做外汇应该看哪一家网站快速排名生客seo
  • 做馋嘴小栈官方网站东台网络推广
  • 做网站便宜沈阳疫情最新消息
  • 广告公司运作模式百度快速seo优化
  • 做网站方法免费文件外链网站
  • 深圳做营销网站公司简介门户网站软文
  • 做mg动画赚钱网站网站按天扣费优化推广
  • 海南省住房和城乡建设厅网站seo优化公司
  • 做企业网站需要什么域名注册要多少钱
  • 微信上怎么做广告推广重庆百度快照优化排名
  • 企业网站搜索优化外下载百度地图2022最新版官方
  • 虐做视频网站2024年8月爆发新的大流行病毒吗
  • 腾讯3大外包公司上海网站seoseodian
  • 手机做推广比较好的网站有哪些目前最牛的二级分销模式