在App平台,与uni-app相比,uni-app x多了不少API,但也还有一些API没有,需要通过插件市场的插件替代。
uni-app x 中不再支持plus和weex的API。对于plus api中一些常用的api,在uni-app x中进行了替换增补。
一些plus api在插件市场有替代:
插件市场有一些抹平plus写法的插件,自定义了一个plus对象,方法内部再调用uni或uts的api,以兼容历史的plus写法,详见
扩展原生API在uni-app x中很简单,以上面的打开schema代码为例。
import android.content.Intent
import android.net.Uri
fun openSystemBrowser(url: String) {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
startActivity(intent)
}
import Intent from 'android.content.Intent';
import Uri from 'android.net.Uri';
function openSystemBrowser(url: string): void {
const intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
}
这里注意几个差别:
import android.content.Intent,而uts是import Intent from 'android.content.Intent'。import后面需要跟名字,from后面需要引号括起来。fun,而uts是functionconst context = UTSAndroid.getUniActivity()!一般推荐使用uni-agent,只需要告诉uni-agent你的需求,定义好调用方式、说明要调用的原生能力,uni-agent就可以给你写出原生插件。
官方的uni api,都是uts插件,这里面很多例子可以参考:https://gitcode.com/dcloud/uni-api
完整的uts插件开发指南,详见