Giter Site home page Giter Site logo

wepy-simple-toast's Introduction

wepy-simple-toast

微信小程序toast组件,适用于wepy,支持Promise。

使用

安装组件

  npm install wepy-simple-toast -S

引入组件

<template>
  <view class="container">
    这里是你的页面内容...
    <toast/>
  </view>
</template>

<script>
import wepy from 'wepy'
import toast from 'wepy-simple-toast'

export default class extends wepy.page {
  components = {
    toast
  }
 }
</script>

调用方法

    // this.$invoke('toast', func, message)
    this.$invoke('toast', 'success', 'simple-toast success')
    //或者 this.$invoke('toast', func, message, options),当前options只有duration(显示的时长)
    this.$invoke('toast', 'success', 'simple-toast success', { duration: 3000 }).then(data => {
        console.log(data)
      })

    // in async function
   let data = await this.$invoke('toast', 'error', 'simple-toast error', { duration: 5000 })
    console.log(data)
  1. func 参数包括 successinfowarningerror
  2. options参数当前只有 duration(显示的时长)

使用进阶

使用MIXIN

  <script>
import wepy from 'wepy'
import toast from 'wepy-simple-toast'

export default class extends wepy.page {
  components = {
    toast
  }
  mixins = [toast.mixin]
 }
</script>

调用方法

    // this.$infoTip(message)
    this.$infoTip('simple-toast info')
    //this.$errorTip(message, options)
    this.$errorTip('simple-toast error', { duration: 3000 }).then(data => {
        console.log(data)
      })
 
    // in async function
    let  data = await this.$warningTip('simple-toast warning', { duration: 3000 })
    console.log(data)
  1. mixin了四个函数 $successTip$infoTip$warningTip$errorTip
  2. options参数当前只有 duration(显示的时长)
  • PS: 如果components的名字不为toast,使用上述Mixin的四个函数时,需要在data里面添加toastTagName:[toast的组件名]

完整示例

点击查看 example.wpy

效果图

example1 example2

wepy-simple-toast's People

Contributors

jardenliu avatar

Stargazers

shaoshilei avatar  avatar  avatar MonkeyZ avatar  avatar DaveCat avatar codeime avatar Karis avatar  avatar

Watchers

 avatar

wepy-simple-toast's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.