1.2.2 • Published 2 years ago

net2view v1.2.2

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

使用(how to use this package)

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

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

<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>
1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago