流浪的菜袅 2023-11-23 14:18 采纳率: 77.5%
浏览 14
已结题

slot插槽在uniapp开发中,手机运行页面是空白的,而内置浏览器运行正常

slot插槽在uniapp开发中,手机运行页面是空白的,而内置浏览器运行正常,但是看文档app端是支持slot的啊
父组件:

<template>
    <view class="body" :style="{height:height+'px'}">
        <view class="header" :style="{height:statusBarHeight+'px'}">
        </view>
        <component :is="navigation" >
            <template v-slot:navigation1>
                取消注册,返回首页1
            </template>
        </component>
    </view>
</template>

子组件:

<template>
    <view class="navigation">
        <!-- navigation1情况  只有左侧内容(字体) -->
        <view class="navigation1 components">
            <slot name="navigation1">
                返回
            </slot>
        </view>
        
        <!-- navigation2情况  只有左侧内容(图标) -->
    </view>
</template>

内置浏览器运行图:

img

手机运行却是空白,报错:

14:11:11.485   <template v-slot> can only appear at the root level inside the receiving component
14:11:11.485   4  |      </view>
14:11:11.488   5  |      <component :is="navigation" >
14:11:11.488   6  |          <template v-slot:navigation1>
14:11:11.490      |    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14:11:11.491   7  |              取消注册,返回首页1
14:11:11.492      |  ^^^^^^^^^^^^^
14:11:11.492   8  |          </template>
14:11:11.494      |  ^^^^^^^^^^^^^

这是为啥啊,裘解答

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 已结题 (查看结题原因) 11月25日
    • 创建了问题 11月23日