主頁 > 企業開發 > 從0搭建vue3組件庫: Input組件

從0搭建vue3組件庫: Input組件

2022-11-12 07:56:46 企業開發

本篇文章將為我們的組件庫添加一個新成員:Input組件,其中Input組件要實作的功能有:

  • 基礎用法
  • 禁用狀態
  • 尺寸大小
  • 輸入長度
  • 可清空
  • 密碼框
  • 帶Icon的輸入框
  • 文本域
  • 自適應文本高度的文本域
  • 復合型輸入框

每個功能的實作代碼都做了精簡,方便大家快速定位到核心邏輯,接下來就開始對這些功能進行一一的實作,

基礎用法

首先先新建一個input.vue檔案,然后寫入一個最基本的input輸入框

<template>
  <div >
    <input  />
  </div>
</template>

然后在我們的 vue 專案examples下的app.vue引入Input組件

<template>
  <div >
    <Input />
  </div>
</template>
<script lang="ts" setup>
import { Input } from "kitty-ui";
</script>

此時頁面上便出現了原生的輸入框,所以需要對這個輸入框進行樣式的添加,在input.vue同級新建style/index.less,Input樣式便寫在這里

.k-input {
  font-size: 14px;
  display: inline-block;
  position: relative;

  .k-input__inner {
    background-color: #fff;
    border-radius: 4px;
    border: 1px solid #dcdfe6;
    box-sizing: border-box;
    color: #606266;
    display: inline-block;
    font-size: inherit;
    height: 40px;
    line-height: 40px;
    outline: none;
    padding: 0 15px;
    width: 100%;
    &::placeholder {
      color: #c2c2ca;
    }

    &:hover {
      border: 1px solid #c0c4cc;
    }

    &:focus {
      border: 1px solid #409eff;
    }
  }
}

image.png

接下來要實作Input組件的核心功能:雙向資料系結,當我們在 vue 中使用input輸入框的時候,我們可以直接使用v-model來實作雙向資料系結,v-model其實就是value @input結合的語法糖,而在 vue3 組件中使用v-model則表示的是modelValue @update:modelValue的語法糖,比如Input組件為例

<Input v-model="tel" />

其實就是

<Input :modelValue="https://www.cnblogs.com/zdsdididi/archive/2022/11/11/tel" @update:modelValue="https://www.cnblogs.com/zdsdididi/archive/2022/11/11/tel = $event" />

所以在input.vue中我們就可以根據這個來實作Input組件的雙向資料系結,這里我們使用setup語法

<template>
  <div >
    <input
      
      :value="https://www.cnblogs.com/zdsdididi/archive/2022/11/11/inputProps.modelValue"
      @input="changeInputVal"
    />
  </div>
</template>
<script lang="ts" setup>
//組件命名
defineOptions({
  name: "k-input",
});
//組件接收的值型別
type InputProps = {
  modelValue?: string | number;
};

//組件發送事件型別
type InputEmits = {
  (e: "update:modelValue", value: string): void;
};

//withDefaults可以為props添加默認值等
const inputProps = withDefaults(defineProps<InputProps>(), {
  modelValue: "",
});
const inputEmits = defineEmits<InputEmits>();

const changeInputVal = (event: Event) => {
  inputEmits("update:modelValue", (event.target as HTMLInputElement).value);
};
</script>

GIF333.gif

到這里基礎用法就完成了,接下來開始實作禁用狀態

禁用狀態

這個比較簡單,只要根據propsdisabled來賦予禁用類名即可

<template>
  <div  :>
    <input
      
      :value="https://www.cnblogs.com/zdsdididi/archive/2022/11/11/inputProps.modelValue"
      @input="changeInputVal"
      :disabled="inputProps.disabled"
    />
  </div>
</template>
<script lang="ts" setup>
//...
type InputProps = {
  modelValue?: string | number;
  disabled?: boolean;
};
//...

//根據props更改類名
const styleClass = computed(() => {
  return {
    "is-disabled": inputProps.disabled,
  };
});
</script>

然后給is-disabled寫些樣式

//...

.k-input.is-disabled {
  .k-input__inner {
    background-color: #f5f7fa;
    border-color: #e4e7ed;
    color: #c0c4cc;
    cursor: not-allowed;
    &::placeholder {
      color: #c3c4cc;
    }
  }
}

image.png

尺寸

按鈕尺寸包括medium,small,mini,不傳則是默認尺寸,同樣的根據propssize來賦予不同類名

const styleClass = computed(() => {
  return {
    "is-disabled": inputProps.disabled,
    [`k-input--${inputProps.size}`]: inputProps.size,
  };
});

然后寫這三個類名的不同樣式

//...
.k-input.k-input--medium {
  .k-input__inner {
    height: 36px;
    &::placeholder {
      font-size: 15px;
    }
  }
}

.k-input.k-input--small {
  .k-input__inner {
    height: 32px;

    &::placeholder {
      font-size: 14px;
    }
  }
}

.k-input.k-input--mini {
  .k-input__inner {
    height: 28px;

    &::placeholder {
      font-size: 13px;
    }
  }
}

繼承原生 input 屬性

原生的inputtype,placeholder等屬性,這里可以使用 vue3 中的useAttrs來實作props穿透.子組件可以通過v-bindprops系結

<template>
  <div  :>
    <input
      
      :value="https://www.cnblogs.com/zdsdididi/archive/2022/11/11/inputProps.modelValue"
      @input="changeInputVal"
      :disabled="inputProps.disabled"
      v-bind="attrs"
    />
  </div>
</template>
<script lang="ts" setup>
//...

const attrs = useAttrs();
</script>

可清空

通過clearable屬性、Input的值是否為空以及是否滑鼠是否移入來判斷是否需要顯示可清空圖示,圖示則使用組件庫的Icon組件

<template>
  <div
    
    @mouseenter="isEnter = true"
    @mouseleave="isEnter = false"
    :
  >
    <input
      
      :disabled="inputProps.disabled"
      v-bind="attrs"
      :value="https://www.cnblogs.com/zdsdididi/archive/2022/11/11/inputProps.modelValue"
      @input="changeInputVal"
    />
    <div
      @click="clearValue"
      v-if="inputProps.clearable && isClearAbled"
      v-show="isFoucs"
      
    >
      <Icon name="error" />
    </div>
  </div>
</template>
<script setup lang="ts">
//...
import Icon from "../icon/index";
//...
//雙向資料系結&接收屬性
type InputProps = {
  modelValue?: string | number;
  disabled?: boolean;
  size?: string;
  clearable?: boolean;
};
//...
const isClearAbled = ref(false);
const changeInputVal = (event: Event) => {
  //可清除clearable
  (event.target as HTMLInputElement).value
    ? (isClearAbled.value = https://www.cnblogs.com/zdsdididi/archive/2022/11/11/true)
    : (isClearAbled.value = false);

  inputEmits("update:modelValue", (event.target as HTMLInputElement).value);
};

//清除input value
const isEnter = ref(true);
const clearValue = https://www.cnblogs.com/zdsdididi/archive/2022/11/11/() => {
  inputEmits("update:modelValue", "");
};
</script>

清除圖示部分 css 樣式

.k-input__suffix {
  position: absolute;
  right: 10px;
  height: 100%;
  top: 0;
  display: flex;
  align-items: center;
  cursor: pointer;
  color: #c0c4cc;
}

image.png

密碼框 show-password

通過傳入show-password屬性可以得到一個可切換顯示隱藏的密碼框,這里要注意的是如果傳了clearable則不會顯示切換顯示隱藏的圖示

<template>
  <div
    
    @mouseenter="isEnter = true"
    @mouseleave="isEnter = false"
    :
  >
    <input
      ref="ipt"
      
      :disabled="inputProps.disabled"
      v-bind="attrs"
      :value="https://www.cnblogs.com/zdsdididi/archive/2022/11/11/inputProps.modelValue"
      @input="changeInputVal"
    />
    <div  v-show="isShowEye">
      <Icon @click="changeType" :name="eyeIcon" />
    </div>
  </div>
</template>
<script setup lang="ts">
//...
const attrs = useAttrs();

//...

//顯示隱藏密碼框 showPassword
const ipt = ref();
Promise.resolve().then(() => {
  if (inputProps.showPassword) {
    ipt.value.type = "password";
  }
});
const eyeIcon = ref("browse");
const isShowEye = computed(() => {
  return (
    inputProps.showPassword && inputProps.modelValue && !inputProps.clearable
  );
});
const changeType = () => {
  if (ipt.value.type === "password") {
    eyeIcon.value = "https://www.cnblogs.com/zdsdididi/archive/2022/11/11/eye-close";
    ipt.value.type = attrs.type || "text";
    return;
  }
  ipt.value.type = "password";
  eyeIcon.value = "https://www.cnblogs.com/zdsdididi/archive/2022/11/11/browse";
};
</script>

這里是通過獲取input元素,然后通過它的type屬性進行切換,其中browseeye-close分別是Icon組件中眼睛開與閉,效果如下

password.gif

帶 Icon 的輸入框

通過prefix-iconsuffix-icon 屬性可以為Input組件添加首尾圖示,

可以通過計算屬性判斷出是否顯示首尾圖示,防止和前面的clearableshow-password沖突.這里代碼做了

<template>
  <div >
    <input
      ref="ipt"
      
      :
      :disabled="inputProps.disabled"
      v-bind="attrs"
      :value="https://www.cnblogs.com/zdsdididi/archive/2022/11/11/inputProps.modelValue"
      @input="changeInputVal"
    />

    <div  v-if="isShowPrefixIcon">
      <Icon :name="inputProps.prefixIcon" />
    </div>
    <div  v-if="isShowSuffixIcon">
      <Icon :name="inputProps.suffixIcon" />
    </div>
  </div>
</template>
<script setup lang="ts">
//...
type InputProps = {
  prefixIcon?: string;
  suffixIcon?: string;
};

//...

//帶Icon輸入框
const isShowSuffixIcon = computed(() => {
  return (
    inputProps.suffixIcon && !inputProps.clearable && !inputProps.showPassword
  );
});
const isShowPrefixIcon = computed(() => {
  return inputProps.prefixIcon;
});
</script>

相關樣式部分

.k-input__suffix,
.k-input__prefix {
  position: absolute;
  right: 10px;
  height: 100%;
  top: 0;
  display: flex;
  align-items: center;
  cursor: pointer;
  color: #c0c4cc;
  font-size: 15px;
}

.no-cursor {
  cursor: default;
}

.k-input--prefix.k-input__inner {
  padding-left: 30px;
}

.k-input__prefix {
  position: absolute;
  width: 20px;
  cursor: default;
  left: 10px;
}

app.vue中使用效果如下

<template>
  <div >
    <Input v-model="tel" suffixIcon="edit" placeholder="請輸入內容" />

    <Input v-model="tel" prefixIcon="edit" placeholder="請輸入內容" />
  </div>
</template>
<script lang="ts" setup>
import { Input } from "kitty-ui";
import { ref } from "vue";
const tel = ref("");
</script>
<style lang="less">
.input-demo {
  width: 200px;
}
</style>

image.png

文本域

type屬性的值指定為textarea即可展示文本域模式,它系結的事件以及屬性和input基本一樣

<template>
  <div  v-if="attrs.type === 'textarea'">
    <textarea
      
      :style="textareaStyle"
      v-bind="attrs"
      ref="textarea"
      :value="https://www.cnblogs.com/zdsdididi/archive/2022/11/11/inputProps.modelValue"
      @input="changeInputVal"
    />
  </div>
  <div
    v-else
    
    @mouseenter="isEnter = true"
    @mouseleave="isEnter = false"
    :
  >
    ...
  </div>
</template>

樣式基本也就是focus,hover改變 border 顏色

.k-textarea {
  width: 100%;

  .k-textarea__inner {
    display: block;
    padding: 5px 15px;
    line-height: 1.5;
    box-sizing: border-box;
    width: 100%;
    font-size: inherit;
    color: #606266;
    background-color: #fff;
    background-image: none;
    border: 1px solid #dcdfe6;
    border-radius: 4px;

    &::placeholder {
      color: #c2c2ca;
    }

    &:hover {
      border: 1px solid #c0c4cc;
    }

    &:focus {
      outline: none;
      border: 1px solid #409eff;
    }
  }
}

image.png

可自適應高度文本域

組件可以通過接收autosize屬性來開啟自適應高度,同時autosize也可以傳物件形式來指定最小和最大行高

type AutosizeObj = {
    minRows?: number
    maxRows?: number
}
type InputProps = {
    autosize?: boolean | AutosizeObj
}

具體實作原理是通過監聽輸入框值的變化來調整textarea的樣式,其中用到了一些原生的方法譬如window.getComputedStyle(獲取原生css物件),getPropertyValue(獲取css屬性值)等,所以原生js忘記的可以復習一下

...
const textareaStyle = ref<any>()
const textarea = shallowRef<HTMLTextAreaElement>()
watch(() => inputProps.modelValue, () => {
    if (attrs.type === 'textarea' && inputProps.autosize) {
        const minRows = isObject(inputProps.autosize) ? (inputProps.autosize as AutosizeObj).minRows : undefined
        const maxRows = isObject(inputProps.autosize) ? (inputProps.autosize as AutosizeObj).maxRows : undefined
        nextTick(() => {
            textareaStyle.value = https://www.cnblogs.com/zdsdididi/archive/2022/11/11/calcTextareaHeight(textarea.value!, minRows, maxRows)
        })
    }

}, { immediate: true })

其中calcTextareaHeight

const isNumber = (val: any): boolean => {
    return typeof val === 'number'
}
//隱藏的元素
let hiddenTextarea: HTMLTextAreaElement | undefined = undefined

//隱藏元素樣式
const HIDDEN_STYLE = `
  height:0 !important;
  visibility:hidden !important;
  overflow:hidden !important;
  position:absolute !important;
  z-index:-1000 !important;
  top:0 !important;
  right:0 !important;
`

const CONTEXT_STYLE = [
    'letter-spacing',
    'line-height',
    'padding-top',
    'padding-bottom',
    'font-family',
    'font-weight',
    'font-size',
    'text-rendering',
    'text-transform',
    'width',
    'text-indent',
    'padding-left',
    'padding-right',
    'border-width',
    'box-sizing',
]

type NodeStyle = {
    contextStyle: string
    boxSizing: string
    paddingSize: number
    borderSize: number
}

type TextAreaHeight = {
    height: string
    minHeight?: string
}

function calculateNodeStyling(targetElement: Element): NodeStyle {
  //獲取實際textarea樣式回傳并賦值給隱藏的textarea
    const style = window.getComputedStyle(targetElement)

    const boxSizing = style.getPropertyValue('box-sizing')

    const paddingSize =
        Number.parseFloat(style.getPropertyValue('padding-bottom')) +
        Number.parseFloat(style.getPropertyValue('padding-top'))

    const borderSize =
        Number.parseFloat(style.getPropertyValue('border-bottom-width')) +
        Number.parseFloat(style.getPropertyValue('border-top-width'))

    const contextStyle = CONTEXT_STYLE.map(
        (name) => `${name}:${style.getPropertyValue(name)}`
    ).join(';')

    return { contextStyle, paddingSize, borderSize, boxSizing }
}

export function calcTextareaHeight(
    targetElement: HTMLTextAreaElement,
    minRows = 1,
    maxRows?: number
): TextAreaHeight {
    if (!hiddenTextarea) {
      //創建隱藏的textarea
        hiddenTextarea = document.createElement('textarea')
        document.body.appendChild(hiddenTextarea)
    }
    //給隱藏的teatarea賦予實際textarea的樣式以及值(value)
    const { paddingSize, borderSize, boxSizing, contextStyle } =
        calculateNodeStyling(targetElement)
    hiddenTextarea.setAttribute('style', `${contextStyle};${HIDDEN_STYLE}`)
    hiddenTextarea.value = https://www.cnblogs.com/zdsdididi/archive/2022/11/11/targetElement.value || targetElement.placeholder ||''
    //隱藏textarea整個高度,包括內邊距padding,border
    let height = hiddenTextarea.scrollHeight
    const result = {} as TextAreaHeight
    //判斷boxSizing,回傳實際高度
    if (boxSizing === 'border-box') {
        height = height + borderSize
    } else if (boxSizing === 'content-box') {
        height = height - paddingSize
    }

    hiddenTextarea.valuehttps://www.cnblogs.com/zdsdididi/archive/2022/11/11/= ''
    //計算單行高度
    const singleRowHeight = hiddenTextarea.scrollHeight - paddingSize

    if (isNumber(minRows)) {
        let minHeight = singleRowHeight * minRows
        if (boxSizing === 'border-box') {
            minHeight = minHeight + paddingSize + borderSize
        }
        height = Math.max(minHeight, height)
        result.minHeight = `${minHeight}px`
    }
    if (isNumber(maxRows)) {
        let maxHeight = singleRowHeight * maxRows!
        if (boxSizing === 'border-box') {
            maxHeight = maxHeight + paddingSize + borderSize
        }
        height = Math.min(maxHeight, height)
    }
    result.height = `${height}px`
    hiddenTextarea.parentNode?.removeChild(hiddenTextarea)
    hiddenTextarea = undefined

    return result
}

這里的邏輯稍微復雜一點,大致就是創建一個隱藏的textarea,然后每次當輸入框值發生變化時,將它的value賦值為組件的textareavalue,最后計算出這個隱藏的textareascrollHeight以及其它padding之類的值并作為高度回傳賦值給組件中的textarea

最后在app.vue中使用

<template>
  <div >
    <Input
      v-model="tel"
      :autosize="{ minRows: 2 }"
      type="textarea"
      suffixIcon="edit"
      placeholder="請輸入內容"
    />
  </div>
</template>

GIFtextarea.gif

復合型輸入框

我們可以使用復合型輸入框來前置或者后置我們的元素,如下所示

image.png

這里我們借助 vue3 中的slot進行實作,其中用到了useSlots來判斷用戶使用了哪個插槽,從而展示不同樣式

import { useSlots } from "vue";

//復合輸入框
const slots = useSlots();

同時template中接收前后兩個插槽

<template>
  <div
    
    @mouseenter="isEnter = true"
    @mouseleave="isEnter = false"
    :
  >
    <div  v-if="slots.prepend">
      <slot name="prepend"></slot>
    </div>
    <input
      ref="ipt"
      
      :
      :disabled="inputProps.disabled"
      v-bind="attrs"
      :value="https://www.cnblogs.com/zdsdididi/archive/2022/11/11/inputProps.modelValue"
      @input="changeInputVal"
    />
    <div  v-if="slots.append">
      <slot name="append"></slot>
    </div>
  </div>
</template>
<script setup lang="ts">
import { useSlots } from "vue";
const styleClass = computed(() => {
  return {
    ["k-input-group k-input-prepend"]: slots.prepend,
    ["k-input-group k-input-append"]: slots.append,
  };
});
//復合輸入框
const slots = useSlots();
</script>

最后給兩個插槽寫上樣式就實作了復合型輸入框

.k-input.k-input-group.k-input-append,
.k-input.k-input-group.k-input-prepend {
  line-height: normal;
  display: inline-table;
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;

  .k-input__inner {
    border-radius: 0 4px 4px 0;
  }

  //復合輸入框
  .k-input__prepend,
  .k-input__append {
    background-color: #f5f7fa;
    color: #909399;
    vertical-align: middle;
    display: table-cell;
    position: relative;
    border: 1px solid #dcdfe6;
    border-radius: 4 0px 0px 4px;
    padding: 0 20px;
    width: 1px;
    white-space: nowrap;
  }

  .k-input__append {
    border-radius: 0 4px 4px 0px;
  }
}

.k-input.k-input-group.k-input-append {
  .k-input__inner {
    border-top-right-radius: 0px;
    border-bottom-right-radius: 0px;
  }
}

app.vue中使用

<template>
    <div >
        <Input v-model="tel" placeholder="請輸入內容">
        <template #prepend>
            http://
        </template>
        </Input>
        <Input v-model="tel" placeholder="請輸入內容">
        <template #append>
            .com
        </template>
        </Input>
    </div>
</template>

總結

一個看似簡單的Input組件其實包含的內容還是很多的,做完之后會發現對自己很多地方都有提升和幫助,

如果你對vue3組件庫開發也感興趣的話可以關注我,組件庫的所有實作細節都在以往文章里,包括環境搭建自動打包發布檔案搭建vitest單元測驗等等,

如果這篇文章對你有所幫助動動指頭點個贊??吧~

原始碼地址

kitty-ui: 一個使用Vite+Ts搭建的Vue3組件庫

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/531854.html

標籤:其他

上一篇:Vue3學習(八)

下一篇:vue中組件化編程

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • IEEE1588PTP在數字化變電站時鐘同步方面的應用

    IEEE1588ptp在數字化變電站時鐘同步方面的應用 京準電子科技官微——ahjzsz 一、電力系統時間同步基本概況 隨著對IEC 61850標準研究的不斷深入,國內外學者提出基于IEC61850通信標準體系建設數字化變電站的發展思路。數字化變電站與常規變電站的顯著區別在于程序層傳統的電流/電壓互 ......

    uj5u.com 2020-09-10 03:51:52 more
  • HTTP request smuggling CL.TE

    CL.TE 簡介 前端通過Content-Length處理請求,通過反向代理或者負載均衡將請求轉發到后端,后端Transfer-Encoding優先級較高,以TE處理請求造成安全問題。 檢測 發送如下資料包 POST / HTTP/1.1 Host: ac391f7e1e9af821806e890 ......

    uj5u.com 2020-09-10 03:52:11 more
  • 網路滲透資料大全單——漏洞庫篇

    網路滲透資料大全單——漏洞庫篇漏洞庫 NVD ——美國國家漏洞庫 →http://nvd.nist.gov/。 CERT ——美國國家應急回應中心 →https://www.us-cert.gov/ OSVDB ——開源漏洞庫 →http://osvdb.org Bugtraq ——賽門鐵克 →ht ......

    uj5u.com 2020-09-10 03:52:15 more
  • 京準講述NTP時鐘服務器應用及原理

    京準講述NTP時鐘服務器應用及原理京準講述NTP時鐘服務器應用及原理 安徽京準電子科技官微——ahjzsz 北斗授時原理 授時是指接識訓通過某種方式獲得本地時間與北斗標準時間的鐘差,然后調整本地時鐘使時差控制在一定的精度范圍內。 衛星導航系統通常由三部分組成:導航授時衛星、地面檢測校正維護系統和用戶 ......

    uj5u.com 2020-09-10 03:52:25 more
  • 利用北斗衛星系統設計NTP網路時間服務器

    利用北斗衛星系統設計NTP網路時間服務器 利用北斗衛星系統設計NTP網路時間服務器 安徽京準電子科技官微——ahjzsz 概述 NTP網路時間服務器是一款支持NTP和SNTP網路時間同步協議,高精度、大容量、高品質的高科技時鐘產品。 NTP網路時間服務器設備采用冗余架構設計,高精度時鐘直接來源于北斗 ......

    uj5u.com 2020-09-10 03:52:35 more
  • 詳細解讀電力系統各種對時方式

    詳細解讀電力系統各種對時方式 詳細解讀電力系統各種對時方式 安徽京準電子科技官微——ahjzsz,更多資料請添加VX 衛星同步時鐘是我京準公司開發研制的應用衛星授時時技術的標準時間顯示和發送的裝置,該裝置以M國全球定位系統(GLOBAL POSITIONING SYSTEM,縮寫為GPS)或者我國北 ......

    uj5u.com 2020-09-10 03:52:45 more
  • 如何保證外包團隊接入企業內網安全

    不管企業規模的大小,只要企業想省錢,那么企業的某些服務就一定會采用外包的形式,然而看似美好又經濟的策略,其實也有不好的一面。下面我通過安全的角度來聊聊使用外包團的安全隱患問題。 先看看什么服務會使用外包的,最常見的就是話務/客服這種需要大量重復性、無技術性的服務,或者是一些銷售外包、特殊的職能外包等 ......

    uj5u.com 2020-09-10 03:52:57 more
  • PHP漏洞之【整型數字型SQL注入】

    0x01 什么是SQL注入 SQL是一種注入攻擊,通過前端帶入后端資料庫進行惡意的SQL陳述句查詢。 0x02 SQL整型注入原理 SQL注入一般發生在動態網站URL地址里,當然也會發生在其它地發,如登錄框等等也會存在注入,只要是和資料庫打交道的地方都有可能存在。 如這里http://192.168. ......

    uj5u.com 2020-09-10 03:55:40 more
  • [GXYCTF2019]禁止套娃

    git泄露獲取原始碼 使用GET傳參,引數為exp 經過三層過濾執行 第一層過濾偽協議,第二層過濾帶引數的函式,第三層過濾一些函式 preg_replace('/[a-z,_]+\((?R)?\)/', NULL, $_GET['exp'] (?R)參考當前正則運算式,相當于匹配函式里的引數 因此傳遞 ......

    uj5u.com 2020-09-10 03:56:07 more
  • 等保2.0實施流程

    流程 結論 ......

    uj5u.com 2020-09-10 03:56:16 more
最新发布
  • 使用Django Rest framework搭建Blog

    在前面的Blog例子中我們使用的是GraphQL, 雖然GraphQL的使用處于上升趨勢,但是Rest API還是使用的更廣泛一些. 所以還是決定回到傳統的rest api framework上來, Django rest framework的官網上給了一個很好用的QuickStart, 我參考Qu ......

    uj5u.com 2023-04-20 08:17:54 more
  • 記錄-new Date() 我忍你很久了!

    這里給大家分享我在網上總結出來的一些知識,希望對大家有所幫助 大家平時在開發的時候有沒被new Date()折磨過?就是它的諸多怪異的設定讓你每每用的時候,都可能不小心踩坑。造成程式意外出錯,卻一下子找不到問題出處,那叫一個煩透了…… 下面,我就列舉它的“四宗罪”及應用思考 可惡的四宗罪 1. Sa ......

    uj5u.com 2023-04-20 08:17:47 more
  • 使用Vue.js實作文字跑馬燈效果

    實作文字跑馬燈效果,首先用到 substring()截取 和 setInterval計時器 clearInterval()清除計時器 效果如下: 實作代碼如下: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta ......

    uj5u.com 2023-04-20 08:12:31 more
  • JavaScript 運算子

    JavaScript 運算子/運算子 在 JavaScript 中,有一些運算子可以使代碼更簡潔、易讀和高效。以下是一些常見的運算子: 1、可選鏈運算子(optional chaining operator) ?.是可選鏈運算子(optional chaining operator)。?. 可選鏈操 ......

    uj5u.com 2023-04-20 08:02:25 more
  • CSS—相對單位rem

    一、概述 rem是一個相對長度單位,它的單位長度取決于根標簽html的字體尺寸。rem即root em的意思,中文翻譯為根em。瀏覽器的文本尺寸一般默認為16px,即默認情況下: 1rem = 16px rem布局原理:根據CSS媒體查詢功能,更改根標簽的字體尺寸,實作rem單位隨螢屏尺寸的變化,如 ......

    uj5u.com 2023-04-20 08:02:21 more
  • 我的第一個NPM包:panghu-planebattle-esm(胖虎飛機大戰)使用說明

    好家伙,我的包終于開發完啦 歡迎使用胖虎的飛機大戰包!! 為你的主頁添加色彩 這是一個有趣的網頁小游戲包,使用canvas和js開發 使用ES6模塊化開發 效果圖如下: (覺得圖片太sb的可以自己改) 代碼已開源!! Git: https://gitee.com/tang-and-han-dynas ......

    uj5u.com 2023-04-20 08:01:50 more
  • 如何在 vue3 中使用 jsx/tsx?

    我們都知道,通常情況下我們使用 vue 大多都是用的 SFC(Signle File Component)單檔案組件模式,即一個組件就是一個檔案,但其實 Vue 也是支持使用 JSX 來撰寫組件的。這里不討論 SFC 和 JSX 的好壞,這個仁者見仁智者見智。本篇文章旨在帶領大家快速了解和使用 Vu ......

    uj5u.com 2023-04-20 08:01:37 more
  • 【Vue2.x原始碼系列06】計算屬性computed原理

    本章目標:計算屬性是如何實作的?計算屬性快取原理以及洋蔥模型的應用?在初始化Vue實體時,我們會給每個計算屬性都創建一個對應watcher,我們稱之為計算屬性watcher ......

    uj5u.com 2023-04-20 08:01:31 more
  • http1.1與http2.0

    一、http是什么 通俗來講,http就是計算機通過網路進行通信的規則,是一個基于請求與回應,無狀態的,應用層協議。常用于TCP/IP協議傳輸資料。目前任何終端之間任何一種通信方式都必須按Http協議進行,否則無法連接。tcp(三次握手,四次揮手)。 請求與回應:客戶端請求、服務端回應資料。 無狀態 ......

    uj5u.com 2023-04-20 08:01:10 more
  • http1.1與http2.0

    一、http是什么 通俗來講,http就是計算機通過網路進行通信的規則,是一個基于請求與回應,無狀態的,應用層協議。常用于TCP/IP協議傳輸資料。目前任何終端之間任何一種通信方式都必須按Http協議進行,否則無法連接。tcp(三次握手,四次揮手)。 請求與回應:客戶端請求、服務端回應資料。 無狀態 ......

    uj5u.com 2023-04-20 08:00:32 more