Skip to content
项目

关于

适用于 Vue 2 的移动端 toast 插件。

网站与应用开发

这些数字如何统计

实测星标增长

24小时
0
7天
0
15天
0
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README_zh.md

原文

vue2-toast

基于vue2的移动端 toast 插件。 English document

Downloads Version

互动演示

使用

安装:

npm install vue2-toast -S

引入:

import 'vue2-toast/lib/toast.css';
import Toast from 'vue2-toast';
Vue.use(Toast);

或者使用配置

import 'vue2-toast/lib/toast.css';
import Toast from 'vue2-toast';
Vue.use(Toast, {
    type: 'center',
    duration: 3000,
    wordWrap: true,
    width: '150px'
});

在组件中使用:

<template>
    <div id="app">
        <button @click="openTop()">top</button>
        <button @click="openCenter()">center</button>
        <button @click="openBottom()">bottom</button>
		<button @click="openLoading()">loading</button>
    </div>
</template>
export default {
    methods:{
        openTop(){
            this.$toast.top('top');
        },
        openCenter(){
            this.$toast.center('center');
        },
        openBottom(){
            this.$toast('bottom');  // or this.$toast.bottom('bottom'); 
        },
        openLoading(){
            this.$loading('loading...');
			let self = this;
	        setTimeout(function () {
	          self.closeLoading()
	        }, 2000)
        },
        closeLoading(){
            this.$loading.close();
        }
    }
}

在 Nuxt.js 中使用

除了 nuxt.js 使用 vue 插件的配置之外,还需要再 nuxt.config.js 添加以下配置

build: {
	vendor: ['vue2-toast'],
	extend (config, ctx) {
	  if (ctx.isClient) {
	    config.resolve.alias['vue'] = 'vue/dist/vue.js';
	  }
	}
}

配置

Vue.use(Toast, [options])
  • type : Toast 的位置. | String | 默认: 'bottom' | 可选值 'top, center,bottom'
  • duration : Number | 默认 2500ms
  • wordWrap : 是否自动换行. | Boolean | 默认: false
  • width : Toast 的宽度. | String | 默认: 'auto'

demo

image

探索相关项目

加载中…