|------components |------toast |------toast.js |------toast.wxml |------toast.wxss
<template name='toast'> <view class="s-toast" wx:if="{{msg}}"> <view class="s-toast-content">{{msg}}</view> </view> </template>
/** * toastMsg 必傳 提示內容 * showTime 非必傳 顯示時間秒 */ function toast(page, toastMsg, showTime) { let timer page.setData({ toastMsg }) showTime = showTime || toastMsg.length / 4 console.log(showTime) clearTimeout(timer) timer = setTimeout(() => { page.setData({ toastMsg: '' }) clearTimeout(timer) }, showTime * 1000) } module.exports = { toast: toast, }
.s-toast-content { position: fixed; left: 50%; color: #fff; width: 500rpx; bottom: 120rpx; background: hsla(0,0%,7%,.7); padding: 15rpx; text-align: center; -webkit-transform: translateX(-50%); transform: translateX(-50%); border-radius: 4rpx; z-index: 6999; }
import { toast } from '../../../project/component/toast/toast.js'
toast(this, '填寫詳細信息')
toast(this,'填寫詳細信息'')
變成前端
toast('填寫詳細信息'')
小程序線上版本vue
點我加羣討論react