npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-toast-indicator

v1.0.5

Published

vue的toast和loading组件

Downloads

5

Readme

vue的toast和loading组件

前言

我们在项目中都会用到toast,loading加载器。特别是在进行移动端的项目开发的时候, 进行异步操作的时候去等待,在必要的时候用toast给用户提示。在app开发中,iOS有成熟的MBProgressHUD插件等等。 在web前端也有很多第三方库也提供了这些组件,比如mint-ui,element-ui等都包含这些组件, 但是存在一个缺点,当我们只需要使用toast,loading组件,并用不到其他组件的时候,我们还是需要安装整个组件库, 会导致我们依赖的第三方库增大。所以我就做了一个轻量级的toast,loading插件vue-toast-indicator。

组件的使用

导入包,全局使用

import {
    Toast,
    Indicator
} from './vue-toast-indicator'

Vue.use(Toast);
Vue.use(Indicator);

toast的使用

 this.$Toast({message:"toast...",position:"bottom"})

indicator使用

加载
 this.$Indicator({message:"加载中..."})
消失 
 setTimeout(()=>{
    this.$Indicator.hidden();
 },600);

组件的原理

封装一个vue组件,创建vue组件,然后动态插入到body节点

举个栗子:

<template>
    <div>
        hello 小猿
    </div>
</template>

<script>
    export default {
        name: 'toast',
    }
</script>
<style>

</style>

上面创建了一个最简单的vue组件

假设我们导入该组件名字是HelloWorld

// 构造组件
const HelloWorldConstructor = Vue.extend(HelloWorld);
export default {

    install(Vue,opt){
        Vue.prototype.$component = function(options = {}) {

            let parentNode = document.createElement("div");
            let instance = new ToastConstructor().$mount(parentNode);

            document.body.appendChild(instance.$el); // 动态插入

            return instance;
    }
    }
}

就是这么简单,上面用到了vue的插件,自定义vue插件需要导出一个install方法

使用就更简单了

import xxx from 'my-lib'

Vue.use(xxx);

在项目中的任意vue组件可以通过this.$component();使用了