微信小程序: 插槽的使用

一、无名插槽的使用

1、 新建components文件夹,新建组件hell, hell.wxml中写入:

         

 

 

2、首页中使用hell组件,先在index.wxml中注册hell:

 

 

    再在index页面中使用:

 

 

  

 

    成功显示如下:

 

    

 

 

 二、具名插槽:指定插槽的位置。

1、 新建components文件夹,新建组件hell, hell.wxml中写入:

       

 2、首页中使用hell组件,先在index.wxml中注册hell:

  

     再在index页面中使用:

   

    此时页面并并不显示“头部”和“底部”,需要我们在hell.js中添加options:{  multipleSlots:true }

  

 

posted @ 2022-02-11 16:26  云里知音  阅读(572)  评论(0)    收藏  举报