Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Hprose in WeChat Mini Programs's Development

Shulou Source: shulou.com Published: 2022-06-01 06:28:44 09月20日 Update

这篇文章主要介绍"怎么在微信小程序开发中使用Hprose"的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇"怎么在微信小程序开发中使用Hprose"文章能帮助大家解决问题。

首先下载微信小程序开发工具,之后安装。

然后按照网上那一堆微信小程序 Hello World 教程创建一个小程序。

接下来我们下载 hprose-html5 或者 hprose-js。推荐使用 hprose-html5 版本,这个版本更小,支持二进制数据传输,而且更快。

可以用 git clone 下载,也可以只下载 dist 目录下的文件,以 hprose-html5 版本为例:

hprose-html5.src.js 是源码版本 hprose-html5.js 是压缩版本

这两个版本都可以用。调试阶段建议用源码版本。但不要使用 hprose-html5.min.js 版本,这个版本是压缩版本的,不支持在微信小程序中编译。

之后,你可以把它们复制到你创建的那个微信小程序的 utils 目录下(复制其中一个就可以),然后将它改名为 hprose.js(这一步可选,只为后面引用的时候,名称统一)。

接下来,打开 pages/index/index.js 文件。

在开头加上:

var hprose = require(\'../../utils/hprose.js\');

然后在 onLoad 事件中加入以下代码:

varclient = hprose.Client.create(http://www.hprose.com/example/, [hello]);client.hello(world,function(result){console.log(result);});

总体看上去是这样的:

//index.js

var hprose = require(\'../../utils/hprose.js\');

//获取应用实例var app = getApp()

Page({

data: {

motto: \'Hello World\',

userInfo: {}

},

//事件处理函数

bindViewTap: function() {

wx.navigateTo({

url: \'../logs/logs\'

})

},

onLoad: function () {

console.log(\'onLoad\')

var client = hprose.Client.create(http://www.hprose.com/example/, [hello]);

client.hello(world, function(result) {

console.log(result);

});

var that = this

//调用应用实例的方法获取全局数据

app.getUserInfo(function(userInfo){

//更新数据

that.setData({

userInfo:userInfo

})

})

}

})

然后点编译,运行。

关于"怎么在微信小程序开发中使用Hprose"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注行业资讯频道,小编每天都会为大家更新不同的知识点。

Tags: Version program development small program data knowledge next event instance file method source code directory industry application support update compile different practical Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux MariaDB Docker OPPO Reno Redmi