npm install php2jsutilsnpm i php2jsutils
1. script标签直接引入
对外暴露变量名称为utils
let {ajax,array_chunk}=utils;
2. import方式引入
import {array_chunk,ajax} from "php2jsutils";
- array_chunk
- array_column
- array_combine
- array_count_values
- array_diff
- array_fill
- array_filter
- array_intersect
- array_unique
- array_last
- array_first
- array_map
- array_merge
- array_pad
- array_pop
- array_product
- array_push
- array_rand
- array_reduce
- array_reverse
- array_search
- array_shift
- array_slice
- array_splice
- array_sum
- array_unshift
- count
- in_array
- range
- shuffle
- is_plain_object
- obj_change_key_case
- obj_diff
- obj_fill
- obj_intersect
- obj_keys
- obj_values
- obj_key_exists
- explode
- implode
- lcfirst
- rtrim
- ltrim
- nl2br
- number_format
- parse_str
- str_contains
- str_end_with
- str_pad
- str_repeat
- str_replace
- str_shuffle
- str_split
- str_start_with
- strstr
- strip_tags
- stripos
- strrchr
- strrev
- strtoupper
- strtolower
- substr
- trim
- ucfirst
- date
- checkdate
- date_add
- date_create_from_format
- date_diff
- date_parse
- date_sub
- getdate
- date_offset_get
- gettimeofday
- localtime
- mktime
- ajax
ajax函数说明
1. 调用方式一
ajax({
url:"http://localhost:3000/posts/1",
method:"get",
headers: {
"Content-Type": "application/json"
}).then(res => {
console.log(res)
});
2. 调用方式二
ajax.get("http://localhost:3000/posts/1",{
headers: {
"Content-Type": "application/json"
}).then(res => {
console.log(res)
});
支持的方法 request,get,post,put,delete
3. 默认参数
url: '',
method: 'get',
data: {},
timeout: 0,
responseType: 'json',// arraybuffer json text bolb
headers: {},
cancelToken: null,
async: true,
adapter: 'xhrAdapter',// xhrAdapter fetchAdapter