npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mylinkpi/uni-composition-api

v0.6.2

Published

uni-composition-api

Downloads

3

Readme

使用须知

时至今日,uniapp 已全面支持 vue3,你应该使用 uniapp-vue3 | uniapp-vite-cli-vue3 uni-composition-api 已完成应有的使命,在此将其归档,望周知。

composition-api of uni-app and Vue2

兼容 UniAppVue2 中 composition-api 的使用,以及提供UniApp生命周期钩子。

该项目会持续更新以及维护至 uni 全面支持 vue3,composition-api。

多端平台兼容性

| app | 微信小程序 | 支付宝小程序 | 百度小程序 | 字节小程序 | QQ小程序 | 快应用 | | :----: | :--------: | :----------: | :--------: | :--------: | :------: | :----: | | √ | √ | 未测试 | 未测试 | 未测试 | 未测试 | 未测试 |

| h5-Safari | Android Browser | 微信浏览器(Android) | QQ浏览器(Android) | Chrome | IE 11+ | Edge | Firefox | pc-Safari | | :-------: | :-------------: | :-----------------: | :---------------: | :----: | :--: | :--: | :-----: | :-------: | | √ | √ | √ | √ | √ | √ | √ | √ | √ |

安装 & 使用

注意:uni-composition-api 仅支持 uni-cli 创建的项目,如使用TypeScript,TypeScript 版本需要 >3.5.1 以上。

npm & ESM

npm i uni-composition-api @vue/composition-api -D

main.js introduce。

import VueCompositionAPI from '@vue/composition-api';
import UniCompositionAPI from 'uni-composition-api';
Vue.use(VueCompositionAPI);
Vue.use(UniCompositionAPI);

index.vue use

<template>
  <div class="index">
    {{ count }}
  </div>
</template>

<script lnag="ts">
import { onLoad } from 'uni-composition-api';
import { defineComponent, ref } from '@vue/composition-api';
export default defineComponent({
  components: {},
  setup() {
    onLoad(() => console.log('---onload---'));
    const count = ref(0);
    return { count };
  },
});
</script>

<style lang="scss"></style>

App.vue 注意事项

typescript模板在入口文件中,使用 defineComponent 定义将会发生错误,原因为 uniapp 在挂载实例添加数据时读取路径不正确,所以入口文件应该使用 Vue.extend 定义文件。

// App.vue
import Vue from 'vue';
import { onLaunch } from 'uni-composition-api';
export default Vue.extend({
  setup() {
    onLaunch(() => {
      console.log('App Launch')
    })
  }
});

生命周期支持

注意:onShareAppMessage,onShareTimeline,onAddToFavorites队列会向后查找返回值, 并自动 return 该返回值。

import {
  // 生命周期钩子 监听页面加载
  onLoad,
  // 生命周期钩子 监听页面显示
  onShow,
  // 生命周期钩子 监听页面初次渲染完成
  onReady,
  // 生命周期钩子 监听页面隐藏
  onHide,
  // 生命周期钩子 监听页面卸载
  onUnload,
  // 页面处理钩子 监听用户下拉动作
  onPullDownRefresh,
  // 页面处理钩子 上拉触底事件的处理函数
  onReachBottom,
  // 页面处理钩子 用户点击右上角转发(需要返回值)
  onShareAppMessage,
  // 页面处理钩子 用户点击右上角转发到朋友圈(需要返回值)
  onShareTimeline,
  // 页面处理钩子 用户点击右上角收藏(需要返回值)
  onAddToFavorites,
  // 页面处理钩子 页面滚动触发事件的处理函数
  onPageScroll,
  // 页面处理钩子 页面尺寸改变时触发
  onResize,
  // 页面处理钩子 当前是 tab 页时,点击 tab 时触发
  onTabItemTap,
  // 页面处理钩子 监听原生标题栏按钮点击事件
  onNavigationBarButtonTap,
  // 页面处理钩子 监听页面返回
  onBackPress,
  // 页面处理钩子 监听原生标题栏搜索输入框输入内容变化事件
  onNavigationBarSearchInputChanged,
  // 页面处理钩子 监听原生标题栏搜索输入框搜索事件,用户点击软键盘上的“搜索”按钮时触发。
  onNavigationBarSearchInputConfirmed,
  // 生命周期回调 监听页面初始化
  onInit,
  // 监听 nvue 页面消息
  onUniNViewMessage,

  // 错误监听函数(App.vue)
  onError,
  // 生命周期回调 监听应用初始化(App.vue)
  onLaunch,
  // 页面不存在监听函数(App.vue)
  onPageNotFound,
  // 监听系统主题变化(App.vue)
  onThemeChange,
  // 未处理的 Promise 拒绝事件监听函数(App.vue)
  onUnhandledRejection,
} from 'uni-composition-api';