zoukankan      html  css  js  c++  java
  • 原生小程序 自定义封装组件

    1.在components自定义文件夹,文件夹里分别包含wxml,wxss,js,json文件 (componetns文件是自己手写的)

    2.wxml与wxss文件按照平常的来就好

    3.js文件

    Component({
      properties:{
             页面上需要动态传递的参数:数据类型
            例如:name:String,
                 或者:sex:{
            type:Number
         }
          },
      methods:{
        //如果页面上有需要触发的事件
        confirm:function(e){
          this.triggerEvent("confirmdata",{
            name:e.currentTarget.dataset.name
          });//confirmdata这里填的什么,引用组件页面就写什么  如果需要传参数,就要后面的内容
        }
      }
    })
     
    4.json文件
    {
      "component": true
    }
    到这里组件就封装完成了!下面就可以开始引用了!!
    在需要引入的文件中
    1.json文件 
    {
       "usingComponents": {
        "dialog": "/pages/component/dialog/dialog"  // "名字随便定义":'组件页面的路径'
      }
    }
    2.wxml文件
    //传的参数放到e.detail的里面
    <dialog  content="请重新登录" bind:confirmdata="handleConfirmDialog">
    </dialog>
    剩下的照常写就可以了!!!
  • 相关阅读:
    indexDB
    跨域 iframe和父页面的通信
    目标
    向往,热情,态度
    dns-prefetch/prefetch/preload/defer/async
    exports 和module.exports转
    【vue】--利用vue-cli--搭建项目------1912--(另一个种)
    【原生】 微任务和宏任务
    【vue】--路由解耦 传值的方式
    【vue】 vue中的query 路由传值的方式
  • 原文地址:https://www.cnblogs.com/mcll/p/11669822.html
Copyright © 2011-2022 走看看