当前位置:   article > 正文

Uni-app x_uniapp x

uniapp x

uni-app x,是下一代 uni-app,是一个跨平台应用开发引擎。

uni-app x 是一个庞大的工程,它包括uts语言、uvue渲染引擎、uni的组件和API、以及扩展机制。

uts是一门类ts的、跨平台的、新语言。uts在iOS端编译为swift、在Android端编译为kotlin、在Web端编译为js。

在Android平台,uni-app x 的工程被编译为kotlin代码,本质上是换了vue写法的原生kotlin应用,在性能上与原生kotlin一致。

uni-app x 是什么? | uni-app-x

常用的方法

uni.$emit & uni.$on

发出和监听事件. 可以用来解耦模块之间的依赖. 

  1. 在添加页面
  2. const addAddress = ()=> {
  3. uni.$emit('addAddressFinished')
  4. uni.navigateBack()
  5. }
  6. // 在使用页面 监听添加完成事件 可以刷新数据等
  7. uni.$on('addAddressFinished', (e) => {
  8. })

defineEmits

子组件向父组件传值

  1. // 子组件
  2. const emits = defineEmits(['selectItem'])
  3. const selectItem = (item) => {
  4. emits('selectItem', item)
  5. }
  6. // 父组件
  7. <rechargeout-validation-popup @select-item="rechargeoutAddressSelectItem"></rechargeout-validation-popup>

获取手机状态栏高度

  1. <template>
  2. <view :style="{width: '100%', height: statusBarHeight + 'px', backgroundColor: 'transparent'}"></view>
  3. </template>
  4. <script setup>
  5. import { ref, reactive } from 'vue'
  6. // 手机屏幕信息
  7. const window = uni.getWindowInfo()
  8. const statusBarHeight = ref(0)
  9. statusBarHeight.value = window.statusBarHeight // 手机状态栏高度
  10. </script>
  11. <style>
  12. </style>

defineProps

父组件向子组件传值

  1. // 需要默认值
  2. const props = defineProps({
  3. current: {
  4. type: Number,
  5. default: 0
  6. }
  7. })
  8. // 不需要需要默认值
  9. const props = defineProps(['title'])
  10. // 有默认值 并且属性必填
  11. const props = defineProps({
  12. popups: {
  13. type: Array,
  14. default: [],
  15. required: true
  16. }
  17. })

根据数据计算高度

  • uni.createSelectorQuery().in(this);
  • nextTick
  • query.select(".tab1-coin-list").boundingClientRect
  1. const getTabHeight = () => {
  2. const query = uni.createSelectorQuery().in(this);
  3. nextTick(() => {
  4. query.select(".tab1-coin-list").boundingClientRect((data) => {
  5. emits('tabHeight', Math.ceil(data.height))
  6. }).exec();
  7. })
  8. }
  9. onMounted(() => {
  10. getTabHeight()
  11. console.log('onMounted')
  12. })
  13. <swiper :style="{ height: `${tabs[activeIndex].height}px` }" :current="activeIndex" >
  14. <swiper-item>
  15. <coin-self-optional @tabHeight="(h) => { tabs[0].height = h }" ></coin-self-optional>
  16. </swiper-item>
  17. </swiper>

Sticky 吸顶 

Sticky 吸顶 | 我的资料管理-uv-ui 是全面兼容vue3+2、nvue、app、h5、小程序等多端的uni-app生态框架

进度条

LineProgress 线形进度条 | 我的资料管理-uv-ui 是全面兼容vue3+2、nvue、app、h5、小程序等多端的uni-app生态框架

Pinia

Pinia基础知识-CSDN博客

跨平台-条件编译

uni-app跨平台-条件编译#ifdef的写法-CSDN博客

页面跳转

uni.navigateTo(options) @navigateto | uni-app-x

UV-UI

Search 搜索 | 我的资料管理-uv-ui 是全面兼容vue3+2、nvue、app、h5、小程序等多端的uni-app生态框架

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/954223
推荐阅读
相关标签
  

闽ICP备14008679号