返回介绍

Ionic4 开关组件 ion-toggle

发布于 2019-11-22 18:04:19 字数 5109 浏览 1515 评论 0 收藏 0

Ionic4项目中我们可以使用Ionic4开关组件ion-toggle对项目进行布局。

ion-toggle官方文档地址:https://ionicframework.com/docs/api/toggle

Toggles change the state of a single option. Toggles can be switched on or off by pressing or swiping them. They can also be checked programmatically by setting the checked property.

ion-toggle 用法(Usage)



















  
    Pepperoni
    
  

  
    Sausage
    
  

  
    Mushrooms
    
  
</ion-list>


















  
    Pepperoni
    
  

  
    Sausage
    
  

  
    Mushrooms
    
  
</ion-list>
import React from 'react';

import { IonToggle, IonList, IonItem, IonLabel } from '@ionic/react';

const Example: React.SFC = () => (
  
    {/*-- Default Toggle --*/}
    

    {/*-- Disabled Toggle --*/}
    

    {/*-- Checked Toggle --*/}
    

    {/*-- Toggle Colors --*/}
    
    
    
    
    

    {/*-- Toggles in a List --*/}
    
      
        Pepperoni
         {}}>
      

      
        Sausage
         {}} disabled={true}>
      

      
        Mushrooms
         {}}>
      
    
  
);

export default Example;

  
  

  
  

  
  

  
  
  
  
  
  

  
  
    
      Pepperoni
      
    

    
      Sausage
      
    

    
      Mushrooms
      
    
  
</template>

ion-toggle 属性(Properties)

checked

Description

If true, the toggle is selected.

Attributechecked
Typeboolean
Defaultfalse

color

Description

The color to use from your application's color palette. Default options are: "primary", "secondary", "tertiary", "success", "warning", "danger", "light", "medium", and "dark". For more information on colors, see theming.

Attributecolor
Typestring | undefined

disabled

Description

If true, the user cannot interact with the toggle.

Attributedisabled
Typeboolean
Defaultfalse

mode

Description

The mode determines which platform styles to use.

Attributemode
Type"ios" | "md"

name

Description

The name of the control, which is submitted with the form data.

Attributename
Typestring
Defaultthis.inputId

value

Description

The value of the toggle does not mean if it's checked or not, use the checked property for that.

The value of a toggle is analogous to the value of a <input type="checkbox">, it's only used when the toggle participates in a native <form>.

Attributevalue
Typenull | string | undefined
Default'on'

ion-toggle 事件(Events)

NameDescription
ionBlurEmitted when the toggle loses focus.
ionChangeEmitted when the value property has changed.
ionFocusEmitted when the toggle has focus.

ion-toggle中的CSS 自定义属性

NameDescription
--backgroundBackground of the toggle
--background-checkedBackground of the toggle when checked
--handle-backgroundBackground of the toggle handle
--handle-background-checkedBackground of the toggle handle when checked

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文