Skip to content

hunter-ji/js-ping

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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>

About

Native js that can be used for h5 to detect the connectivity of the target address

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published