包含标签 typescript 中的文章

typescript 将 json 序列化为 querystring 格式

typescript 将 json 序列化为 querystring 格式 使用 typescript 时, 需要同时安装 @types/qs 和 qs 1 yarn add @types/qs qs demo 1 2 3 4 5 6 7 8 9 const params = qs.stringify({ namespace: namespace, replicas: replicas, }) const u = `/deployments/${name}/replicas?${params}` console.log("Uuuuu::::", u); // Uuuuu:::: /deployments/failed-nginx/replicas?namespace=default&replicas=3……

阅读全文

axios get 请求携带 body 数据

axios get 请求携带 json body 数据 在 http 标准协议中, GET 请求 本身是可以携带 Body 数据 。 至于 GET 请求携带的数据能不能被获取, 还是要看接受端 后端 是否处理。 在 gin-gonic/gin 框架中, GET 请求默认就不会处理 body 中的数据, 只能通过 query 表单数据传递。 然而不同的浏览器对于 URL 长度的限制也不同,一般是 1024 个字符, 1. 有些时候需要携带的数据可能超……

阅读全文

typescript vue3 项目容器化实战

typescript vue3 项目容器化实战 在前端容器化的时候, 有一个绕不开的问题: 容器返回的后端地址应该怎么设置。 静态编译到所有文件中, 肯定是不可取的, 总不能后端变更一个访问域名,前端都要重新构建一次镜像吧? 由于 js (typescript 编译后 ) 实际是运行在 用户的浏览器上, 所以也不能像后端一样读取环境变量。 所以, 通过 html <meta> 标签……

阅读全文

typescript 中使用 @ 路径别名

typescript 中使用 @ 路径别名 使用路径别名 @/some/path/index.ts 可以很简单的表示一个文件的绝对路径(其实是相对于 @ 的相对路径) 安装 @types/node 1 yarn add @types/node 配置 tsconfig.json , 一下是基于 vite2 项目配置 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 { "compilerOptions": { // ... , "types": [ "node" ], // https://github.com/vitejs/vite/issues/279 "paths": { "@/*": [ "./src/*", ] } }, // ... } 就可以在 ts 文件中使用 @ 别名引入了。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17……

阅读全文

typescript 中的 const 断言

typescript 中的 const assertions const assertions - TypeScript 3.4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 // vue3 const dnsProviders = { "aliyun.com": "alidns", "tencent.com": "dnspod" } let data = reactive({ rootDomain: "aliyun.com" as const }) let dnsProvider = computed( () => { return dnsProviders[data.rootDomain] } ) 这个时候会, 提示 7053 错误, data.rootDomain 具有 any type, 不能被用作 key。 解决这个问题使用, 需要使用 typescript 中 const assertion 类型推断。 const assertion 类型推断。 字面量类型推断: 其类型为字面值类型。 例如这里的 hello 的类型是……

阅读全文

typescript 中的时间处理

typescript 中的时间处理 在 typescript/ javasctipt 中, 时间 是一个 构造 函数, 需要通过 const dt = new Date(xxx) 进行初始化创建时间对象。 创建时间对象 1 2 3 4 5 6 7 8 9 10 // 获取当前时间对象 const now = new Date() // 将字符串时间转换为 Date 时间对象 const timeStr = '2021-08-23T02:42:17Z' const dt = new Date(timeStr) // 根据数字创建时间 const dt2 = new Date(Date.UTC(2006, 0, 2, 15, 4, 5)); console.log("event:::", dt2); 时间操作 获取时间对象的属性值 通过 getXXX() 方法, 可以……

阅读全文

福利派送

  • (免费星球)「运维成长路线」

  • 又拍云免费 CDN

最近文章

分类

标签

其它