React+ionic

2020-05-26  本文已影响0人  随风Guard

安装

npm install -g @ionic/cli

ionic start myApp blank --type=react

cd myApp

运行

ionic serve

路由跳转

-普通跳转

<IonButton href="/button">button按钮

-传值跳转

this.props.history.push({pathname:'/button',state:{name:'张三'}})

this.props.history.go(); //防止页面不刷新

-子组件接受参数

this.props.location.state.name

proxy代理服务

src文件夹下创建 setupProxy.js文件,不需要引用

npm i http-proxy-middleware   //安装插件

const proxy = require('http-proxy-middleware')

module.exports = function(app) {

    app.use(

        proxy('/api', {  //`api`是需要转发的请求

            target: 'https://xxxx.com/',  // 这里是接口服务器地址

            changeOrigin: true,

            pathRewrite: {

                  '^/api': ''  //省略/api

           }

      })

   )

}

上一篇 下一篇

猜你喜欢

热点阅读