当前位置: 首页 > article >正文

微信小程序 slot 不显示

问题:创建组件,使用带名字的slot,页面调用组件使用slot不显示

源码:

组件xml


<view class="p-item br24" style="{{style}}">
    <slot name="right" wx:if="{{!custBottom}}"></slot>
    <view class="right-bottom" wx:else>
      <view class="flex_row_st numchange">
        <text class="minus">-</text>
        <input type="number" class="num-input" value="100"></input>
        <text class="add">+</text>
      </view>
      <button size="mini" class="primary-color btn" bindtap="DoSignOK">添加</button>
    </view>
  </view>
</view>

JS:根据条件判断是否使用slot

Component({
  properties: {
    custBottom: {type: Boolean, value: false}
  },
 
  data: {},
  lifetimes: {
    attached() {
      console.log(">>> 被页面调用", this.data)
    }
  },
  methods: {
  }
});

 页面调用

 <view>
    <productCard custBottom="{{true}}">
      <view slot="right">TEST</view>
    </productCard>

    <productCard></productCard>

  </view>

解决:

组件加上多slot配置,置为true

options: {
  multipleSlots: true
},

 修改:

Component({
  properties: {
    custBottom: {type: Boolean, value: false}
  },
options: {
  multipleSlots: true //增加此配置slot
},
 
  data: {},
  lifetimes: {
    attached() {
      console.log(">>> 被页面调用", this.data)
    }
  },
  methods: {
  }
});

效果:slot出来了。


http://www.kler.cn/news/108438.html

相关文章:

  • 私有云:【3】NFS存储服务器的安装
  • Linux内核驱动开发的需要掌握的知识点
  • 虚拟化、容器与Docker基本介绍以及安装部署(Docker 基本管理)
  • 前端、HTTP协议(重点)
  • 阿里云企业邮箱基于Spring Boot快速实现发送邮件功能
  • SQLi靶场
  • C语言每日一题(21)删除排序数组中的重复项
  • maven之父子工程版本控制案例实战,及拓展groupId和artifactId的含义
  • 67 内网安全-域横向smbwmi明文或hash传递
  • MacOS将Node.js升级到最新版本
  • 服务器之日常整活
  • Go语言用Resty库编写的音频爬虫代码
  • MatlabR2019b安装教程
  • 《Attention Is All You Need》阅读笔记
  • Hadoop、Hive安装
  • 【Qt6】为什么“转到槽函数“能在没有添加connect的情况下,把一个组件或对象和一个函数关联起来?
  • 力扣labuladong——一刷day12
  • 拿捏面试官,高频接口自动化测试面试题总结(附答案)狂收offer...
  • 是顺流还是逆流?未来物流作业是否将被机器人全面取代?
  • 安装 GMP、NTL、CTMalloc ,编译 OpenFHE
  • matlab将十六进制转换为十进制(hex2dec函数)
  • 公司电脑如何限制安装软件
  • 【网络安全 --- 文件上传靶场练习】文件上传靶场安装以及1-5关闯关思路及技巧,源码分析
  • 基于入侵杂草算法的无人机航迹规划-附代码
  • 左神算法题系列:动态规划机器人走路
  • 设置GIT代理
  • ES6 模块化编程 详解
  • 新一代AI技术,引领医疗智能革新共筑未来医疗生态
  • 红米电脑硬盘剪切
  • API商品数据接口调用实战:爬虫与数据获取