zoukankan      html  css  js  c++  java
  • 微信小程序之自定义组件与使用

    一般我们在定义了一个组件之后,为了复用,需要将它导出以提供给其他页面使用。

    组件导出的关键字是

    exprot default

    没有加default时,例如:

    export class Template{}

    当然,你可以在单个js文件里声明多个组件,例如Templates.js

    export class Template{}
    export class AnotherTemplate{}

    这样在其他文件引用时,需要使用{}符号且组件名称必修和class名称一样,像这样子:

    import {Template,AnotherTemplate} from './components/Templates';

    而加default时,例如:

    export default class Template{}

    然后在其他文件引用,像这样子:

    import Template from './components/Templates';

    你也可以为这个组件另起一个别名,像这样子:

    import TheTemplate from './components/Templates';

    但是每个文件里只能有个default组件,可以包含其他非default组件:

    export default class Template{}
    export class AnotherTemplate{}

    然后引用的时候,如下:

    import Template,{AnotherTemplate} from './components/Templates';

    总结

    • 有default和没有default的区别在于:有default在引用时可以自定义名称,而没有default时需要使用{}括起来且名称必修和class名称一致
    • 每个文件里只能有一个default组件,但可以有多个非default组件
  • 相关阅读:
    debug 调试Windows service服务调试
    Windows Service 创建 发布
    SQL Server 触发器
    c# core api 配置redis
    Core Api 搭建Swagger
    c# core api 自定义特性
    本地iis配置;,NET系统本地发布发布 通过配置路由器可以实现公网访问
    c# 线程的几种实现方式
    c# Thread.Sleep();
    2019创建 core api 加配置swagger
  • 原文地址:https://www.cnblogs.com/min-min-min/p/6999340.html
Copyright © 2011-2022 走看看