zoukankan      html  css  js  c++  java
  • react-native 点击按钮进行交互

    在api/index.js里面封装了一个方法:
    / login登录接口
    export const loginFromApiAsync = function (a,b) {
    return fetch(URL+'/vhc/cust/api/login',{
    method: "POST",
    headers: {
    Accept: "application/json",
    "Content-type": "application/json",
    "X-App-Platform": "app"
    },
    body: JSON.stringify({
    account: a,
    password: b
    })

    })
        .then(res => res.json())
        .then(res => {
            return res;
        })
        .catch(err => {
            console.log(err);
        })
    

    };

    在登录页面引入后使用
    import {loginFromApiAsync} from "../api";

    export default class Login extends Component {
    
    constructor(props){
        super(porps);
        this.state = {
            account:''
        }
    }
    
    //定义一个方法
    _loginFromApiAsync(){
    
    //要获取state里面的数据account, 需要render里面使用函数时绑定this。如果不绑定this,this.state.account取不到
    let a = this.state.account;
    
        loginFromApiAsync()
            .then( data => {
                //data成功后返回的数据
            }
        )
    }
    
    render(){
        <Text
            onPress = { this._loginFromApiAsync.bind(this)_}
        >点击</Text>
    }
    

    }

  • 相关阅读:
    iOS_UIImage的方向(imageOrientation)
    iOS-LaunchImage启动页
    iOS_UIImage_毛玻璃效果
    iOS_常用C语言函数
    iOS_UIImage_Gif的合成
    iOS_UIImage_Gif的分解
    iOS_UIImge_Gif的展示
    iOS_UIImage_jpg<-->png转换
    Mysql学习第三天
    Mysql学习第二天
  • 原文地址:https://www.cnblogs.com/xk-g/p/9519133.html
Copyright © 2011-2022 走看看