1***@qq.com
1***@qq.com
  • 发布:2025-07-30 14:51
  • 更新:2025-07-30 17:12
  • 阅读:37

uniappX中插槽的使用

分类:uni-app x

<slot :item="item"></slot> ,使用插槽提示[app-android]组件solt不支持属性‘item’,问题:uniappX是否支持使用插槽,如果不支持如何实现插槽中:item=类似的功能

2025-07-30 14:51 负责人:无 分享
已邀请:
DCloud_UNI_JBB

DCloud_UNI_JBB

支持的啊,下面的代码我在4.75版本的hx测试是正常运行的

<template>  
    <view class="imgbox" id="imgbox">  
        <child>  
            <template v-slot:header="{data}">  
                <view class="test">{{data}}</view>  
            </template>  
        </child>  
        <child>  
            <template v-slot:header>  
                <view class="test">123</view>  
            </template>  
        </child>  
    </view>  
</template>  

<script setup lang="uts">  
   import child from './child.uvue'  
</script>
<template>    
    <view>    
        <slot name="header" :data="data"></slot>    
    </view>    
</template>    

<script lang="uts">    
    export default {    
        name:"child",    
        data() {    
            return {    
               data: 'data'  
            }    
        },    
        methods: {    
            test(str : string){    
                console.log("调用组件:"+str);    
            }    
        }    
    }    
</script>  
1***@qq.com

1***@qq.com (作者)

hbuildx版本4.75,刚运行到手机上展示没问题,但是写代码的时候有警告如图

1***@qq.com

1***@qq.com (作者)

另外问一下,可以在list-view中item中使用插槽吗,会影响item的循环使用或者数据展示也有问题吗

要回复问题请先登录注册