美文网首页
React+ionic

React+ionic

作者: 随风Guard | 来源:发表于2020-05-26 12:48 被阅读0次

安装

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

           }

      })

   )

}

相关文章

  • React+ionic

    安装 npm install -g @ionic/cli ionic start myApp blank --ty...

网友评论

      本文标题:React+ionic

      本文链接:https://www.haomeiwen.com/subject/eabmahtx.html