current position:Home>Harmonyos+django data transmission ------------- note 1

Harmonyos+django data transmission ------------- note 1

2022-07-25 20:26:29Maruko_ four hundred and twenty-eight

1. The front-end configuration

1.config.json

1.deviceConfig

"default": {
      "process": "com.huawei.hiworld.example",
      "supportBackup": false,
      "network": {
        "cleartextTraffic": true
      }
    }

2.  module

"reqPermissions": [
      {
        "name": "ohos.permission.GET_NETWORK_INFO"
      },
      {
        "name": "ohos.permission.SET_NETWORK_INFO"
      },
      {
        "name": "ohos.permission.INTERNET"
      }
    ],

2. page

1.hml

 

<div class="container">
        <text class="txt"> Click button </text>
        <button class="button01" onclick="onClick">
             Request and response 
        </button>
        <text>{
   {winfo}}</text>
</div>

 2.js

Need to install :qs library 、fetch

npm install qs
npm install querystring

js Content

import fetch from '@system.fetch';
import qs from 'querystring';
export default{
    data:{
        winfo:"",
    },
    onClick(){
        fetch.fetch({
            // Back end interface ,AppReq1 by views Class name in    
            url:'http://“ Own request port ”/“ establish app The name of ”/AppReq1/' ,
            data:qs.stringify({'id':'1'}),
            responseType:"json",
            method:"POST",
            success:(resp)=>{
                this.winfo = resp.data;
                console.log(" Return the data :"+this.winfo)
            },
            fail:(resp)=>{
                this.winfo = resp.data;
                console.log(" Failed to get data :"+this.winfo)
            }
        })
    }
}

copyright notice
author[Maruko_ four hundred and twenty-eight],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/201/202207191111371127.html

Random recommended