Giter Site home page Giter Site logo

js-ping's Introduction

js-ping

Intro

js-ping是一个简单的用来在前端检测网络是否通畅的工具。

js-ping is a simple tool used to check whether the network is smooth on the front end.

Usage

Install the package first.

npm i js-ping

Import package.

import { ping } from "js-ping";

Then use it.

ping("http://localhost:5000").then(res => {
  console.log(res)
})
  .catch(err => {
  console.log(err)
})

If successful, the returned result is in json format.

{
  "status": 200,
  "response": "Hello, World !"
}

If it fails, the return result is in string format.

"error"
"timeout"

Example

<template>
  <div id="app">
    <a href="https://github.com/Kuari/js-ping" target="_blank">js-ping</a>
  </div>
</template>

<script>
import { ping } from "js-ping";

export default {
  mounted() {
    ping("http://localhost:5000").then(res => {
          console.log(res)
        })
        .catch(err => {
          console.log(err)
        })
  }
}
</script>

js-ping's People

Contributors

hunter-ji avatar

Stargazers

Ayaka avatar

Watchers

James Cloos avatar  avatar

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.