feat: 添加eslint和prettier配置文件
parent
47fc92ebc7
commit
22b57e9fa7
|
|
@ -0,0 +1 @@
|
||||||
|
{}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"tabWidth": 2,
|
||||||
|
"printWidth": 120,
|
||||||
|
"bracketSpacing": true
|
||||||
|
}
|
||||||
|
|
@ -17,17 +17,14 @@
|
||||||
|
|
||||||
## 快速开始
|
## 快速开始
|
||||||
|
|
||||||
1. 确保本地安装有如下软件,推荐最新版本。
|
1. 确保本地安装有如下软件,推荐最新版本。备注:Pnpm 在 NodeJS v16+ 版本可通过 corepack enable 命令开启,低版本请通过 npm install pnpm 命令安装。
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 官网:https://git-scm.com/
|
# 官网:https://git-scm.com/
|
||||||
git
|
git
|
||||||
|
|
||||||
# 官网:https://nodejs.org/en
|
# 官网:https://nodejs.org/en
|
||||||
node
|
node + pnpm
|
||||||
|
|
||||||
# 备注:在NodeJS v16+版本可通过 corepack enable 命令开启,低版本请通过 npm install pnpm 命令安装
|
|
||||||
pnpm
|
|
||||||
```
|
```
|
||||||
|
|
||||||
2. 拉取模板
|
2. 拉取模板
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
{
|
{
|
||||||
"hash": "3930064b",
|
"hash": "f14be980",
|
||||||
"browserHash": "71254bdf",
|
"browserHash": "16a0d7a2",
|
||||||
"optimized": {
|
"optimized": {
|
||||||
"vue": {
|
"vue": {
|
||||||
"src": "../../../../../../../node_modules/.pnpm/vue@3.3.4/node_modules/vue/dist/vue.runtime.esm-bundler.js",
|
"src": "../../../../node_modules/.pnpm/vue@3.3.4/node_modules/vue/dist/vue.runtime.esm-bundler.js",
|
||||||
"file": "vue.js",
|
"file": "vue.js",
|
||||||
"fileHash": "9e6f557b",
|
"fileHash": "e275f4f9",
|
||||||
"needsInterop": false
|
"needsInterop": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// ../../../node_modules/.pnpm/@vue+shared@3.3.4/node_modules/@vue/shared/dist/shared.esm-bundler.js
|
// node_modules/.pnpm/@vue+shared@3.3.4/node_modules/@vue/shared/dist/shared.esm-bundler.js
|
||||||
function makeMap(str, expectsLowerCase) {
|
function makeMap(str, expectsLowerCase) {
|
||||||
const map2 = /* @__PURE__ */ Object.create(null);
|
const map2 = /* @__PURE__ */ Object.create(null);
|
||||||
const list = str.split(",");
|
const list = str.split(",");
|
||||||
|
|
@ -256,7 +256,7 @@ var replacer = (_key, val) => {
|
||||||
return val;
|
return val;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ../../../node_modules/.pnpm/@vue+reactivity@3.3.4/node_modules/@vue/reactivity/dist/reactivity.esm-bundler.js
|
// node_modules/.pnpm/@vue+reactivity@3.3.4/node_modules/@vue/reactivity/dist/reactivity.esm-bundler.js
|
||||||
function warn(msg, ...args) {
|
function warn(msg, ...args) {
|
||||||
console.warn(`[Vue warn] ${msg}`, ...args);
|
console.warn(`[Vue warn] ${msg}`, ...args);
|
||||||
}
|
}
|
||||||
|
|
@ -1410,7 +1410,7 @@ function computed(getterOrOptions, debugOptions, isSSR = false) {
|
||||||
}
|
}
|
||||||
var tick = Promise.resolve();
|
var tick = Promise.resolve();
|
||||||
|
|
||||||
// ../../../node_modules/.pnpm/@vue+runtime-core@3.3.4/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js
|
// node_modules/.pnpm/@vue+runtime-core@3.3.4/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js
|
||||||
var stack = [];
|
var stack = [];
|
||||||
function pushWarningContext(vnode) {
|
function pushWarningContext(vnode) {
|
||||||
stack.push(vnode);
|
stack.push(vnode);
|
||||||
|
|
@ -9125,7 +9125,7 @@ var ssrUtils = _ssrUtils;
|
||||||
var resolveFilter = null;
|
var resolveFilter = null;
|
||||||
var compatUtils = null;
|
var compatUtils = null;
|
||||||
|
|
||||||
// ../../../node_modules/.pnpm/@vue+runtime-dom@3.3.4/node_modules/@vue/runtime-dom/dist/runtime-dom.esm-bundler.js
|
// node_modules/.pnpm/@vue+runtime-dom@3.3.4/node_modules/@vue/runtime-dom/dist/runtime-dom.esm-bundler.js
|
||||||
var svgNS = "http://www.w3.org/2000/svg";
|
var svgNS = "http://www.w3.org/2000/svg";
|
||||||
var doc = typeof document !== "undefined" ? document : null;
|
var doc = typeof document !== "undefined" ? document : null;
|
||||||
var templateContainer = doc && doc.createElement("template");
|
var templateContainer = doc && doc.createElement("template");
|
||||||
|
|
@ -9488,7 +9488,7 @@ var defineSSRCustomElement = (options) => {
|
||||||
};
|
};
|
||||||
var BaseClass = typeof HTMLElement !== "undefined" ? HTMLElement : class {
|
var BaseClass = typeof HTMLElement !== "undefined" ? HTMLElement : class {
|
||||||
};
|
};
|
||||||
var VueElement = class extends BaseClass {
|
var VueElement = class _VueElement extends BaseClass {
|
||||||
constructor(_def, _props = {}, hydrate2) {
|
constructor(_def, _props = {}, hydrate2) {
|
||||||
super();
|
super();
|
||||||
this._def = _def;
|
this._def = _def;
|
||||||
|
|
@ -9659,7 +9659,7 @@ var VueElement = class extends BaseClass {
|
||||||
};
|
};
|
||||||
let parent = this;
|
let parent = this;
|
||||||
while (parent = parent && (parent.parentNode || parent.host)) {
|
while (parent = parent && (parent.parentNode || parent.host)) {
|
||||||
if (parent instanceof VueElement) {
|
if (parent instanceof _VueElement) {
|
||||||
instance.parent = parent._instance;
|
instance.parent = parent._instance;
|
||||||
instance.provides = parent._instance.provides;
|
instance.provides = parent._instance.provides;
|
||||||
break;
|
break;
|
||||||
|
|
@ -10619,7 +10619,7 @@ var initDirectivesForSSR = () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ../../../node_modules/.pnpm/vue@3.3.4/node_modules/vue/dist/vue.runtime.esm-bundler.js
|
// node_modules/.pnpm/vue@3.3.4/node_modules/vue/dist/vue.runtime.esm-bundler.js
|
||||||
function initDev() {
|
function initDev() {
|
||||||
{
|
{
|
||||||
initCustomFormatter();
|
initCustomFormatter();
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -6,14 +6,14 @@ import { defineConfig } from "vitepress";
|
||||||
*/
|
*/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
lang: "zh-CN",
|
lang: "zh-CN",
|
||||||
title: "绝弹博客",
|
title: "AppnifyVUE",
|
||||||
description: "一位前端开发者的博客",
|
description: "一位前端开发者的博客",
|
||||||
/**
|
/**
|
||||||
* 主题配置
|
* 主题配置
|
||||||
* @see https://vitepress.dev/reference/default-theme-config
|
* @see https://vitepress.dev/reference/default-theme-config
|
||||||
*/
|
*/
|
||||||
themeConfig: {
|
themeConfig: {
|
||||||
logo: "/juetan.jpg",
|
logo: "/favicon.ico",
|
||||||
search: {
|
search: {
|
||||||
provider: "local",
|
provider: "local",
|
||||||
options: {
|
options: {
|
||||||
|
|
@ -43,29 +43,16 @@ export default defineConfig({
|
||||||
link: "/",
|
link: "/",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: "前端开发",
|
text: "项目概览",
|
||||||
link: "/front-end/",
|
link: "/overview/",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: "后端开发",
|
text: "开发文档",
|
||||||
items: [
|
link: '/dev'
|
||||||
{
|
|
||||||
text: "测试1",
|
|
||||||
link: "/test1",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: "测试2",
|
|
||||||
link: "/test2",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: '日常记录',
|
text: '关于',
|
||||||
link: '/'
|
link: '/about'
|
||||||
},
|
|
||||||
{
|
|
||||||
text: "开发工具",
|
|
||||||
link: "/dev-tools",
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
sidebar: {
|
sidebar: {
|
||||||
|
|
|
||||||
|
|
@ -93,159 +93,4 @@
|
||||||
--vp-custom-block-tip-border: var(--vp-c-brand);
|
--vp-custom-block-tip-border: var(--vp-c-brand);
|
||||||
--vp-custom-block-tip-text: var(--vp-c-brand-lightest);
|
--vp-custom-block-tip-text: var(--vp-c-brand-lightest);
|
||||||
--vp-custom-block-tip-bg: var(--vp-c-brand-dimm);
|
--vp-custom-block-tip-bg: var(--vp-c-brand-dimm);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Component: Algolia
|
|
||||||
* -------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
.DocSearch {
|
|
||||||
--docsearch-primary-color: var(--vp-c-brand) !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.Layout {
|
|
||||||
background-color: #f1f3f5;
|
|
||||||
}
|
|
||||||
|
|
||||||
#VPContent .VPDoc.has-aside .content-container {
|
|
||||||
max-width: initial;
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.VPNav {
|
|
||||||
border-bottom: 1px solid #f1f3f5;
|
|
||||||
background: #fff;
|
|
||||||
}
|
|
||||||
|
|
||||||
.curtain,
|
|
||||||
.aside-curtain {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
#VPContent .aside {
|
|
||||||
padding-left: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (min-width: 640px) {
|
|
||||||
.vp-doc div[class*="language-"] {
|
|
||||||
border-radius: 2px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#VPSidebarNav {
|
|
||||||
margin-top: 20px;
|
|
||||||
background: #fff;
|
|
||||||
padding: 16px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#VPSidebarNav .group {
|
|
||||||
padding-top: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#app .VPSidebar {
|
|
||||||
width: calc((100% - (var(--vp-layout-max-width) - 64px)) / 2 + var(--vp-sidebar-width) - 20px);
|
|
||||||
padding-right: 24px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#app .aside-container {
|
|
||||||
padding-top: calc(var(--vp-nav-height) + var(--vp-layout-top-height, 0px) + var(--vp-doc-top-height, 0px) + 20px);
|
|
||||||
}
|
|
||||||
|
|
||||||
#app .aside {
|
|
||||||
max-width: 228px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#app .pager-link {
|
|
||||||
border-radius: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#app .VPNavBarTitle.has-sidebar .title {
|
|
||||||
border-bottom-color: transparent;
|
|
||||||
}
|
|
||||||
|
|
||||||
#app .VPMenu {
|
|
||||||
border-radius: 2px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Component: Home
|
|
||||||
* -------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
::-webkit-scrollbar {
|
|
||||||
width: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
::-webkit-scrollbar-track {
|
|
||||||
background: #f1f1f1;
|
|
||||||
}
|
|
||||||
|
|
||||||
::-webkit-scrollbar-thumb {
|
|
||||||
background: #888;
|
|
||||||
border-radius: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
::-webkit-scrollbar-thumb:hover {
|
|
||||||
background: #555;
|
|
||||||
}
|
|
||||||
|
|
||||||
.content img {
|
|
||||||
border: 1px solid #e1f1f1;
|
|
||||||
border-radius: 2px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.item {
|
|
||||||
width: 100%;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
.link {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.text {
|
|
||||||
width: 100%;
|
|
||||||
overflow: hidden;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
|
||||||
font-size: 14px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.VPSidebarItem {
|
|
||||||
/* padding: 0 8px; */
|
|
||||||
}
|
|
||||||
|
|
||||||
.items > .VPSidebarItem.level-1 {
|
|
||||||
margin-top: 4px;
|
|
||||||
padding: 0 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.items > .VPSidebarItem.level-1.is-active {
|
|
||||||
background: hsl(204 100% 95% / 1);
|
|
||||||
/* padding: 0 8px; */
|
|
||||||
border-radius: 2px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.vp-doc tr:nth-child(2n) {
|
|
||||||
background-color: transparent;
|
|
||||||
}
|
|
||||||
|
|
||||||
.vp-doc h2 {
|
|
||||||
margin: 32px 0 16px;
|
|
||||||
border-top: none;
|
|
||||||
padding-top: 0;
|
|
||||||
border-bottom: 1px solid var(--vp-c-divider);
|
|
||||||
padding-bottom: 8px;
|
|
||||||
letter-spacing: -0.02em;
|
|
||||||
line-height: 32px;
|
|
||||||
font-size: 24px;
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
.vp-doc a {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
.VPNavBarTitle .title {
|
|
||||||
font-weight: 400;
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,85 +0,0 @@
|
||||||
# 日常开发中如何利用 EJS 模板引擎辅助生成代码?
|
|
||||||
|
|
||||||
在如今的前端开发中,[EJS](https://ejs.bootcss.com/) 已经是一个过时的开发方案,但其实在辅助开发方面还是用处的。话不多说,接下来以一个例子来感受下。
|
|
||||||
|
|
||||||
## 例子
|
|
||||||
|
|
||||||
在日常开发中,有时候会遇到后端有一些枚举字典的定义,前端也要进行相应的配置。例如在做权限功能时,后端给了我们下面的权限码数据:
|
|
||||||
|
|
||||||
```json
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"id": 1,
|
|
||||||
"code": "access:readAbc",
|
|
||||||
"authName": "读取权限",
|
|
||||||
"level": 1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 2,
|
|
||||||
"code": "access:writeAbc",
|
|
||||||
"authName": "写入权限"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
```
|
|
||||||
|
|
||||||
我们需要把他做成枚举的形式, 也就是下面的形式:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
/**
|
|
||||||
* 权限码
|
|
||||||
*/
|
|
||||||
export const enum AuthEnum {
|
|
||||||
/**
|
|
||||||
* 读取权限
|
|
||||||
*/
|
|
||||||
ReadAbc = "access:readAbc",
|
|
||||||
/**
|
|
||||||
* 写入权限
|
|
||||||
*/
|
|
||||||
WriteAbc = "access:writeAbc",
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
那么如何从这项无聊的工作中解放出来呢,操作也比较简单。
|
|
||||||
|
|
||||||
1\. 首先打开一个能编译 EJS 的在线网站, 例如 [One Compiler](https://onecompiler.com/ejs)。
|
|
||||||

|
|
||||||
|
|
||||||
2\. 根据目标数据结构整理下代码,点击`RUN`按钮即可。
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
<%
|
|
||||||
let items = [
|
|
||||||
{
|
|
||||||
"id": 1,
|
|
||||||
"code": "access:readAbc",
|
|
||||||
"authName": "读取权限",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 2,
|
|
||||||
"code": "access:writeAbc",
|
|
||||||
"authName": "写入权限",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
items = items.map(item => {
|
|
||||||
let key = item.code.substring(7);
|
|
||||||
key = key.charAt(0).toUpperCase() + key.slice(1)
|
|
||||||
return { ...item, key }
|
|
||||||
})
|
|
||||||
-%>
|
|
||||||
/**
|
|
||||||
* 权限码
|
|
||||||
*/
|
|
||||||
export const enum DaEnum {
|
|
||||||
<% items.forEach((i, index) => { -%>
|
|
||||||
/**
|
|
||||||
* <%= i.authName %>
|
|
||||||
*/
|
|
||||||
<%= i.key %> = '<%= i.code %>',
|
|
||||||
<% }) -%>
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 结语
|
|
||||||
|
|
||||||
以上这是一个简单的例子,但在命令行工具进行页面模板的生成方面可能用得比较多。另外,EJS 的语法也不难,在一些重复性的代码生成方面还是不错的。
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
前端
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 67 KiB |
|
|
@ -1,112 +0,0 @@
|
||||||
# 从new xx()和new xx的区别中,整理JS中操作符的优先级
|
|
||||||
|
|
||||||
|
|
||||||
## 问题
|
|
||||||
最近在工作中写日期格式化时,遇到一个问题,先来看下面的代码:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
// 写法一
|
|
||||||
new Date().toISOString
|
|
||||||
|
|
||||||
// 写法二
|
|
||||||
new Date.toISOString;
|
|
||||||
```
|
|
||||||
执行如下:
|
|
||||||
|
|
||||||
and-new.png)
|
|
||||||
|
|
||||||
猜测是优先级的问题,然后在MDN找到了[答案](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/Operator_precedence#%E6%B1%87%E6%80%BB%E8%A1%A8),它们确实是两个不同的优先级,如下图:
|
|
||||||
|
|
||||||
-and-new.png)
|
|
||||||
|
|
||||||
以上,方式一中的 `.` 优先级最高,但其左边需要先求值,因而先执行`new Date()`得到实例,再返回实例上的`toISOString`属性;而方式二中的 `. `优先级也是最高,但其左边不用求值,因而可以先执行`Date.toISOString`得到`toISOString`值(Date上不存在该属性,因此该值为undefined),再尝试进行`new toISOString`操作时报错发生。
|
|
||||||
|
|
||||||
## 优先级
|
|
||||||
我印象中的运算符只有四十几个,没想到在MDN里面找到的有六十几个。说实话,上面的运算符以前真没注意过,趁着空闲我决定将这些运算符整理下,整理后总体分为下面的五大类:
|
|
||||||
|
|
||||||
### 一级运算符
|
|
||||||
大部分是一元操作符。
|
|
||||||
|
|
||||||
| 运算符 | 类型 | 说明
|
|
||||||
| :--- | :--- | ---
|
|
||||||
| ( … ) | 分组 | 优先级最高的运算符
|
|
||||||
| … . … | 成员访问 | 静态访问
|
|
||||||
| [] | 需计算的成员访问 | 动态访问
|
|
||||||
| new xx() | new(带参数列表) | 实例化
|
|
||||||
| () | 函数调用 | 函数调用
|
|
||||||
| ?. | 可选链(Optional chaining) | `a?.b`类似于`a === null \|\| a === void 0 ? void 0 : a.b;`
|
|
||||||
| new … | new(无参数列表) | 实例化
|
|
||||||
| … ++ | 后置递增 | 先返回再+1,例如 `let a = 1; const b = a++; // b: 1 a: 2`。比较常见的是在for循环中进行后置递增。
|
|
||||||
| … -- | 后置递减 | 同上
|
|
||||||
| ! … | 逻辑非 (!) |
|
|
||||||
| ~ … | 按位非 (~) |
|
|
||||||
| + … | 一元加法 (+) | 可用于把字符串转换为数值,例如`+'1'`将得到`1`。
|
|
||||||
| - … | 一元减法 (-) | 同上
|
|
||||||
| ++ … | 前置递增 | 与后置递增不同,先执行+1再返回
|
|
||||||
| -- … | 前置递减 | 同上
|
|
||||||
| typeof … | typeof | 返回值只有这几个:string \| number \| boolean \| undefined \| null \| function \| object
|
|
||||||
| void … | void | 比较常见的是使用`void 0`代替undefined,因为在以前undefined是可以作为变量名使用的。
|
|
||||||
| delete … | delete | 删除对象的属性
|
|
||||||
| await … | await | 等待某个promise执行成功
|
|
||||||
|
|
||||||
### 算符运算符
|
|
||||||
| 运算符 | 类型 | 说明
|
|
||||||
| :--- | :--- | ---
|
|
||||||
| … ** … | 幂 (**) |
|
|
||||||
| … * … | 乘法 (*) |
|
|
||||||
| … / … | 除法 (/) |
|
|
||||||
| … % … | 取余 (%) |
|
|
||||||
| … + … | 加法 (+) |
|
|
||||||
| … - … | 减法 (-) |
|
|
||||||
| … << … | 按位左移 (<<) | 通常用于二进制数据的移位, 例如:`(4)<<1` 将得到`8`。过程:十进制`4`转换为二进制`100`, 左移一位得到`1000`,再转换为十进制即为`8`。
|
|
||||||
| … >> … | 按位右移 (>>) | 同上
|
|
||||||
| … >>> … | 无符号右移 (>>>) | 同上
|
|
||||||
| … < … | 小于 (<) | 对于数值,比较大小
|
|
||||||
| … <= … | 小于等于 (<=) |
|
|
||||||
| … > … | 大于 (>) |
|
|
||||||
| … >= … | 大于等于 (>=) |
|
|
||||||
|
|
||||||
### 比较运算符
|
|
||||||
| 运算符 | 类型 | 说明
|
|
||||||
| :--- | :--- | ---
|
|
||||||
| … in … | in | 判断某个属性是否存在于对象上,会顺着原型链进行查找,可以用`Object.prototype.hasOwnProperty.call(obj, 'xx')`进行检测自身的属性是否存在。
|
|
||||||
| … instanceof … | instanceof | 判断右边的对象,是否在左边对象的原型链上。
|
|
||||||
| … == … | 相等 (==) | 左右两边的值可能会先做隐式转换,再进行比较,例如: `'1' == 1 //true`
|
|
||||||
| … != … | 不相等 (!=) | 同上
|
|
||||||
| … === … | 一致/严格相等 (===) | 左右两边的值不做隐式转换,直接比较,例如:`'1' === 1 // false`
|
|
||||||
| … !== … | 不一致/严格不相等 (!==) | 同上
|
|
||||||
|
|
||||||
### 布尔运算符
|
|
||||||
| 运算符 | 类型 | 说明
|
|
||||||
| :--- | :--- | ---
|
|
||||||
| … & … | 按位与 (&) | 常用于对二进制数值进行操作
|
|
||||||
| … ^ … | 按位异或 (^) |
|
|
||||||
| … \| … | 按位或 (\|) |
|
|
||||||
| … && … | 逻辑与 (&&) |
|
|
||||||
| … \|\| … | 逻辑或 (||) |
|
|
||||||
| … ?? … | 空值合并 (??) | 当左边的值不为undefined或null时,返回左边,否则返回右边, 具体代码可能是这样的\n: `a !== null && a !== void 0 ? a : b;` |
|
|
||||||
|
|
||||||
### 赋值运算符
|
|
||||||
| 运算符 | 类型 | 说明
|
|
||||||
| :--- | :--- | ---
|
|
||||||
| … ? … : … | 条件(三元)运算符 | 可以在简单场景中代替if/else使用,不过自从出了??运算符,这个运算符用的比较少
|
|
||||||
| … = … | 赋值 |
|
|
||||||
| … += … |
|
|
||||||
| … -= … |
|
|
||||||
| … **= … |
|
|
||||||
| … *= … |
|
|
||||||
| … /= … |
|
|
||||||
| … %= … |
|
|
||||||
| … <<= … |
|
|
||||||
| … >>= … |
|
|
||||||
| … >>>= … |
|
|
||||||
| … &= … |
|
|
||||||
| … ^= … |
|
|
||||||
| … |= … |
|
|
||||||
| … &&= … |
|
|
||||||
| … ||= … |
|
|
||||||
| … ??= … |
|
|
||||||
| … , … | 逗号 / 序列 | 优先级最低的运算符,由于其会返回最后一个值,在某些简短操作中也会用到,例如:`const map = items.reduce((m, i) => (m[i.id]=i,m), {})`
|
|
||||||
|
|
||||||
## 结语
|
|
||||||
优先级的重要性不言而喻,往后还是要多多温习。
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 12 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 53 KiB |
|
|
@ -3,15 +3,15 @@
|
||||||
layout: home
|
layout: home
|
||||||
|
|
||||||
hero:
|
hero:
|
||||||
name: "绝弹博客"
|
name: "Appnify"
|
||||||
text: ""
|
text: ""
|
||||||
tagline: 一位前端开发者的博客
|
tagline: 基于 vue3 + vite 的后台管理系统模板
|
||||||
actions:
|
actions:
|
||||||
- theme: brand
|
- theme: brand
|
||||||
text: 首页
|
text: 概览
|
||||||
link: /markdown-examples
|
link: /markdown-examples
|
||||||
- theme: alt
|
- theme: alt
|
||||||
text: 测试页面
|
text: 开发文档
|
||||||
link: /api-examples
|
link: /api-examples
|
||||||
image:
|
image:
|
||||||
src: /assets/td.svg
|
src: /assets/td.svg
|
||||||
|
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 4.9 KiB |
11
package.json
11
package.json
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"name": "common",
|
"name": "starter-vue",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|
@ -9,14 +9,7 @@
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"new": "cd ./scripts/plop && plop",
|
"new": "cd ./scripts/plop && plop",
|
||||||
"api": "tsx ./scripts/openapi/index.ts",
|
"api": "tsx ./scripts/openapi/index.ts",
|
||||||
"release": "release-it --config ./scripts/release/index.cjs",
|
"release": "release-it --config ./scripts/release/index.cjs"
|
||||||
"docs:dev": "vitepress dev docs",
|
|
||||||
"docs:build": "vitepress build docs",
|
|
||||||
"docs:preview": "vitepress preview docs"
|
|
||||||
},
|
|
||||||
"prettier": {
|
|
||||||
"tabWidth": 2,
|
|
||||||
"printWidth": 120
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@arco-design/web-vue": "^2.44.4",
|
"@arco-design/web-vue": "^2.44.4",
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,9 @@ class Constant<T extends Item[]> {
|
||||||
constructor(public raw: T) {}
|
constructor(public raw: T) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 格式化枚举值
|
* 格式化值
|
||||||
* @param value 值
|
* @param value 值
|
||||||
* @param key 属性名,默认为label
|
* @param key 对应属性名,默认为label
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
fmt<K extends T[number]["value"]>(value: K, key?: keyof T[number]) {
|
fmt<K extends T[number]["value"]>(value: K, key?: keyof T[number]) {
|
||||||
|
|
@ -27,23 +27,17 @@ class Constant<T extends Item[]> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取枚举值对应的对象
|
* 获取值对应的对象
|
||||||
* @param value 枚举值
|
* @param value 值
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
get(value: any) {
|
get(value: any) {
|
||||||
return this.raw.find((item) => item.value === value);
|
return this.raw.find((item) => item.value === value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建实例
|
|
||||||
* @param items 对象数组
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
static from<T extends Item[]>(items: T) {
|
|
||||||
return new Constant(items);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Constant };
|
const defineConstants = <T extends Item[]>(items: T) => {
|
||||||
|
return new Constant(items);
|
||||||
|
};
|
||||||
|
|
||||||
|
export { defineConstants };
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Constant } from "@/utils";
|
import { defineConstants } from "./defineConstants";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 性别枚举
|
* 性别枚举
|
||||||
|
|
@ -21,7 +21,7 @@ enum Gender {
|
||||||
/**
|
/**
|
||||||
* 性别
|
* 性别
|
||||||
*/
|
*/
|
||||||
const GenderDict = Constant.from([
|
const Genders = defineConstants([
|
||||||
{
|
{
|
||||||
value: Gender.Man,
|
value: Gender.Man,
|
||||||
label: "男",
|
label: "男",
|
||||||
|
|
@ -39,5 +39,5 @@ const GenderDict = Constant.from([
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
export { Gender, GenderDict };
|
export { Gender, Genders };
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1 +1,2 @@
|
||||||
export * from "./gender";
|
export * from "./gender";
|
||||||
|
export * from "./defineConstants";
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,2 @@
|
||||||
export * from "./constant";
|
|
||||||
export * from "./delConfirm";
|
export * from "./delConfirm";
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue