HarmonOS JS学习笔记(遇坑)-数据请求

210 阅读1分钟

config.json里需开启权限

文档中心

import fetch from '@system.fetch'

export default {
  data: {
    responseData: 'NA',
    url: "test_url",
  },
  fetch: function () {
    var that = this;
    fetch.fetch({
      url: that.url,
      success: function(response) {
        console.info("fetch success");
        that.responseData = JSON.stringify(response);
      },
      fail: function() {
        console.info("fetch fail");
      }
    });
  }
}

json数据要转一下

JSON.parse(res.data)