# net2view

> automatically render view by soliciting network data

Latest version **1.2.2** (published 2022-03-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install net2view
pnpm add net2view
yarn add net2view
bun add net2view
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.2 |
| Published | 2022-03-02 |
| First published | 2022-02-25 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | xmh0511 |

## Links

- npm: https://www.npmjs.com/package/net2view
- npm.io page: https://npm.io/package/net2view

## Recent versions

- 1.2.2 (latest) — 2022-03-02
- 1.2.1 — 2022-03-02
- 1.2.0 — 2022-03-02
- 1.1.0 — 2022-03-02
- 1.0.0 — 2022-02-25

## README

### 使用（how to use this package）

> 如何使用   
> First, we should initialize the network module in this package in main.js file  

````javascript
import {network} from "net2view";  

network.init("https://127.0.0.1:8080",()=>{
	// 返回一个权限验证的键值对表达式
	// an expression that returns a pair in terms of the form for the authorization that you expect
    return {token: query("tokenid") } 
},(r)=>{
	// 判断请求是否正确的表达式
	// an expression that judges whether the request is ok
    return r.data.status === "success"; 
})
````

> 如何在组件中使用  
> how to use this package in your component 

````javascript
<template>
  <view>
     {{TryRead(list.value,"msg.data")}}
  </view>
</template>
<script setup>
import {
    hook,
    TryRead,
    hookBadModel
} from "net2view";
import {
    reactive, 
    onBeforeMount
} from "vue";

// define the event for a model
const eventDriver = reactive({  //定义事件驱动
    method:"get",
    api:"/getlist",
    update:0,
    /*
	//url参数 
	// option for parameters in url, the form should be {key:value}
    data:null,   

	// header头参数
	// option for headers in request header, the form should be {key:value}
    header:null  
	             
    */
});

// define the model associated with the above event
const list = reactive({  //定义事件驱动
    value:{}
})

// hook的第一第二参数支持数组形式，要求事件和对应的数据模型一一对应
// the first argument can be of array type, as well as the second argument
// when they are of array type, they shall correspond   

hook(eventDriver,list,(driver,model)=>{  
	  // callback for the success requests
      // 请求成功后的回调
});

hookBadModel(list,(model)=>{  

	   // 监测到list对应的事件请求失败时的回调
	  //hookBadModel的一个参数支持批量监测加入到hook的model

	  // this will be evaluated when the event associated with "list" will fail

	  // the first argument can be of array type
});

onBeforeMount(()=>{
	  // 组件挂载前，驱动数据
	  // drive eventDriver, which will automatically update the corresponding view.
      eventDriver.update++; 
});
/*
    // 等价于 list.value.msg.data, 前者是安全访问
    // the use of this api is equivalent to `list.value.msg.data` except that the former can safely access the data
    TryRead(list.value,"msg.data") 	
*/
</script>
````

---
_Source: https://npm.io/package/net2view · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
