1、創(chuàng)建啟動react項(xiàng)目:
npx create-react-app 項(xiàng)目名 //創(chuàng)建
npm install //安裝依賴
npm start //啟動
2、跨域代理:
【1】文檔:https://create-react-app.dev/docs/proxying-api-requests-in-development/
npm install http-proxy-middleware --save
【2】src/setupProxy.js:
const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function(app) {
app.use(
'/ajax',
createProxyMiddleware({
target: 'https://m.maoyan.com',
changeOrigin: true,
})
);
app.use(
'/api',
createProxyMiddleware({
target: 'https://i.maoyan.com',
changeOrigin: true,
})
);
};
文章來源地址http://www.zghlxwxcb.cn/news/detail-525077.html
文章來源:http://www.zghlxwxcb.cn/news/detail-525077.html
到了這里,關(guān)于【react】創(chuàng)建啟動react項(xiàng)目和跨域代理:的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!