株式会社ヴァンデミックシステム

Blog

<スポンサーリンク>

呼び出す側

<コンポーネント名 props名="値"/>の要領で書く

<td><GetPod name="vamdemic111aaa-app"/></td>

 

呼び出される側

  • propsに入る
  • this.props.nameで使うことができる

 

class GetPod extends Component {
    constructor(props) {
        super(props);
        this.state = {
            podstatus: ''
        }
    }

    // renderの前に実行される
    componentWillMount() {
    const json = {"Name":this.props.name};
    const convert_json = JSON.stringify(json);
    const obj = JSON.parse(convert_json);
    console.log(obj)
    console.log(this.props.name)
    const request = axios.create({
        baseURL: "http://127.0.0.1:1323",
        headers: {
            'Content-Type': 'application/json',
        },
        responseType: 'json',
        method: "GET"
   })

   request.get("/getpodstatus", obj)
        .then(request => {
           this.setState({
               // podstatus: request.data.items[0].status.phase
               podstatus: request.data.items[0].status.phase
           })
           console.log(this.state.podstatus)
       })
    }

    // コンポーネントが呼ばれたらstateを返すようにする
    render() {
        return <p>{this.state.podstatus}</p> ;
    }
}

 

 

<スポンサーリンク>

コメントを残す

Allowed tags:  you may use these HTML tags and attributes: <a href="">, <strong>, <em>, <h1>, <h2>, <h3>
Please note:  all comments go through moderation.

*

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)