Develop Paper
  • Program
  • Server
  • Development Tool
  • Blockchain
  • Database
  • Artificial Intelligence
  • Blogs
Position: Home > Program > Content

Fat programmer: from design drawings to NPM publishing components

Time:2022-5-26

What virtue does the design drawing get?

Fat programmer: from design drawings to NPM publishing components

Fat programmer: from design drawings to NPM publishing components


What did YY in my mind

We can see from the design drawings that there are two kinds of toast at present. When packaging components, we should consider that other styles of components may be added later, so we should try to be extensible when designing

  • There must be a type attribute, which controls which type of component is displayed
  • There must be a text attribute, which can be used to pass in different copybooks
  • There must be a timeout attribute. How many MS components will disappear after being passed in through the attribute

Your pants are off. It’s time to get to the point. Go to the code

<template>
  <transition name="fade">
    <div class="toastWrap" v-if="isShow"  v-cloak>
      <div class="toast-content no-wrap">
        //Use the type passed in to tell the component which subcomponent to use
        <component :is="getType()" :text="textinfo"></component>
      </div>
    </div>
  </transition>
</template>
<script>
  const toastText = {
    props: ['text'],
    template: `<div class="text" v-text="text"></div>`
  }
  const toastIcon = {
    props: ['text'],
    template: `<div class="icon-wrap"><div class="icon-img"></div><div class="icon-text" v-text="text"></div></div>`
  }
  export default {
    props: {
      show: {
        type: Boolean,
        default: true,
        required: false
      },
      type: {
        type: String,
        default: 'toastText', //toastText,toastIcon
        required: false
      },
      timeout: {
        type: Number,
        default: 1600,
        required: false
      },
      text: {
        type: String,
        Default: 'submitting',
        required: false
      }
    },
    data: function() {
      return {
        isShow: true,
        textinfo: '',
      }
    },
    mounted: function() {
      this.showToast()
    },
    methods: {
      getType() {
        return this.type
      },
      /**
       *If passed through an external parameter, the external parameter is displayed; otherwise, the default parameter is displayed
       * @param text
       * @param timeout
       * @returns {Promise}
       */
      showToast(text = this.text, timeout = this.timeout) {
        this.textinfo = text
        return new Promise((reslove,reject) => {
          setTimeout(() => {
            this.isShow = false
            //Release news
            this.$emit('toast-cb')
            reslove()
          }, timeout)
        })
      }
    },
    components: {
      toastText,
      toastIcon
    },
  }
</script>
<style lang="css">
  .fade-enter-active,.fade-leave-active {
    transition: opacity 0.5s;
  }
  .fade-enter,.fade-leave-to {
    opacity: 0;
  }
  .toastWrap {
    position: fixed;
    width: 100%;
    height: 100%;
    z-index: 100;
  }
  .toastWrap .toast-content {
    border-radius: 7px;
    background: rgba(0,0,0,0.7);
    padding: 15px 10px;
    color: #fff;
    font-size: 14px;
    text-align: center;
    position: absolute;
    left: 50%;
    top: 50%;
    -webkit-transform: translateX(-50%) translateY(-50%);
    -moz-transform: translateX(-50%) translateY(-50%);
    -ms-transform: translateX(-50%) translateY(-50%);
    -o-transform: translateX(-50%) translateY(-50%);
    transform: translateX(-50%) translateY(-50%);
  }
  .icon-wrap {
    text-align: center;
    font-size: 14px;
  }
  .icon-img {
    width: 30px;
    height: 30px;
    line-height: 30px;
    margin: auto auto 5px;
    background: url('./img/icon-loading.png') center no-repeat;
    background-size: 80%;
    animation: myrotate 0.8s infinite linear;
  }
  .icon-text {
    white-space: nowrap;
  }
  .no-wrap {
    white-space: nowrap;
  }
  @-moz-keyframes myrotate {
    0% {
      -webkit-transform: rotate(0deg);
    }
    100% {
      -webkit-transform: rotate(360deg);
    }
  }
  @-webkit-keyframes myrotate {
    0% {
      -webkit-transform: rotate(0deg);
    }
    100% {
      -webkit-transform: rotate(360deg);
    }
  }
  @-o-keyframes myrotate {
    0% {
      -webkit-transform: rotate(0deg);
    }
    100% {
      -webkit-transform: rotate(360deg);
    }
  }
  @keyframes myrotate {
    0% {
      -webkit-transform: rotate(0deg);
    }
    100% {
      -webkit-transform: rotate(360deg);
    }
  }
</style>

What other improvements?

The icon of toasticon sub component is not dynamically set. If the toast of other icons is designed later, the attribute can be proposed and passed through parameters


NPM release

Before releasing the package, you must first have an NPM account
Enter NPM addUser in the terminal, prompt for account, password and email, and then prompt for successful creation
Then, execute NPM init to generate package json

NPM publish // issue the command

Ending without ending

toast-vue-mobile

github

Tags: A design chart, Account number, assembly, attribute, Ending

Recommended Today

[redis] redis’ basic principles and solutions of cache breakdown, cache penetration and cache avalanche

Article catalogue Cache penetration principle resolvent Buffer breakdown principle resolvent Cache avalanche principle resolvent Cache penetration principle The data corresponding to the key does not exist in the database. Every request for the key cannot be obtained from the cache. The request will access the database. A large number of visits to the database may […]

  • [play with cloud function] get through GitHub to enterprise wechat
  • The intelligent financial management system was built by the CEO of a technology company
  • Scenarios that must be considered when designing a stable microservice system
  • ES6: template string
  • Springboot integrates activiti’s own online process editor, the whole program source code, leave approval
  • How does rxjs help business development?
  • On logical selector — the parent selector is coming!
  • Leetcode (12) insert interval
  • Dart series: create library package
  • Java zero foundation introductory to proficient learning tutorial, the most comprehensive explanation of Java Foundation
Pre: Python magic method__ call__ Research
Next: Spring security plays a flower! Two ways of DIY login

    Tags

    address algorithm array assembly attribute Browser c Character string Client code command configuration file container data Database Definition Edition element Example file function java javascript Journal link linux Memory method Model Modular mysql node object page parameter php Plug-in unit project python Route source code The server Thread time user

    Recent Posts

    • [redis] redis’ basic principles and solutions of cache breakdown, cache penetration and cache avalanche
    • C language sequence point problem
    • The idea compilation project always prompts that the package cannot be found. Delete the dependency in ieda, update maven, and re import. Ensure that the local warehouse location is the location of the project dependency reference
    • About interpersonal relationships
    • Network counting Experiment III

    Recent Comments

    • Blogs on Answer for Java: why is array not passed by reference?
    • douya0808 on Answer for Java: why is array not passed by reference?
    • joyqi on Under the ES6 specification, the repeat function reports an error invalid count value
    • joyqi on Under the ES6 specification, the repeat function reports an error invalid count value
    • joyqi on Under the ES6 specification, the repeat function reports an error invalid count value

    Categories

    • .NET Core
    • Agile Development
    • Algorithm And Data Structure
    • Android
    • Apple MAC
    • Architecture Design
    • Artificial Intelligence
    • ASP.NET
    • Backend
    • Blockchain
    • C
    • C#
    • C++
    • Cloud
    • Database
    • Design Pattern
    • Development Tool
    • Embedded
    • Erlang
    • Freshman
    • Game
    • Golang
    • HTML/CSS
    • HTML5
    • Informal Essay
    • Information Security
    • IOS
    • Java
    • JavaScript
    • JSP
    • Linux
    • Lua
    • MongoDB
    • MsSql
    • MySql
    • Network Security
    • OOP
    • oracle
    • Other DB
    • Other Technologies
    • Other Technology
    • Perl
    • PHP
    • Program
    • Python
    • Redis
    • Regular Expression
    • Ruby
    • Rust
    • SAP
    • Server
    • Software Testing
    • Team Management
    • VBS
    • VUE
    • WEB Front End
    • Windows
    • XML/XSLT
  • java
  • php
  • python
  • linux
  • windows
  • android
  • ios
  • mysql
  • html
  • .net
  • github
  • node.js

Copyright © 2022 Develop Paper All Rights Reserved      Sitemap    About DevelopPaper    Privacy Policy    Contact Us