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

fymock

v1.0.1

Published

A simple mock applied to Vue

Downloads

9

Readme

fymock-cli

介绍

vue项目无侵入引入mockjs的简易cli工具

软件架构

软件架构说明

安装教程

step1

进入到vue项目的根目录

step2
npm i fymock -g
fymock init
or
npx fymock init
step3
.env.development文件
 # mock status
 MOCK_STATUS = true
 MOCK_TIMEOUT = 200
step4
vue.config.js文件
module.exports = {
    devServer: {
        before: process.env.MOCK_STATUS === 'true' && require('./mock/index')
    }
}

大功告成,运行项目即可~

使用说明

1.mockjs模板数据

在vue项目根目录下自动生成的mock文件夹中,有个modules文件夹,里面预先放置login.json5、user.json5两个模块的mock数据(ps:如不喜欢可以删除重建)

{
    // H5 登录
    'login/h5': {
       'user_id|+1': 1, // 用户id
       name: '@cname', // 用户昵称
       avatar: "@image('200x100', '#894FC4', '#FFF', 'png', '@cname')", // 用户头像
       login_time: '@datetime', // 用户登录时间
    }
    // ...
      // 这里可以添加更多的接口模板
      // 键名对应接口名
      // 键值对应mock模板
}

其中'login/h5'为接口名,其后为对应的mock模板,模板数据修改保存会激活热重载,无需重启vue服务

vscode安装json5插件,会添加对.json5格式文件的高亮显示

2.调用
xxx.vue
 axios.post('/api/login/h5').then(res=>{
     console.log(res) // 获取到的数据
 }).catch(error => console.log(error))

其中‘/api/login/h5’为标识符‘api’与modules文件夹中对应的模板键名‘login/h5’的拼接

目前所有接口默认为post请求

3.延迟

目前默认延迟响应时间为200ms,可设置.env.development文件中MOCK_TIMEOUT进行更改(一般情况下,不回去变更),更改完成需要重启vue项目

4.关闭mock

可设置.env.development文件中MOCK_STATUS=false进行关闭mock,更改完成需要重启vue项目