YuCheng's Site
    • Posts
    • [DB] Database
      • [SQL] CTE
      • [SQL] Merge
      • [SQL] Ranking
    • [OS] Linux
      • [Arch] 安裝(Virtualbox)
      • [CentOS] 設定網路靜態IP
      • [Ubuntu] SSH 連線
      • [Ubuntu] 設定網路靜態IP
    • [Secure] 安全性議題
      • [授權] OAuth 2.0 簡介
      • [授權] OAuth 2.0 授權許可
    • [Web] Web 相關
      • [Keycloak] docker 安裝
      • [Web] FontForge 造難字
      • [Web] 敏感性 GET 參數
      • [Web] 敏感性 GET 參數
    • [前端] Javascript
      • [JS] Array 常用方法
      • [JS] Object 常用方法
      • [JS] 各種模組(module)
      • [JS] 提升與暫時性死區
      • [JS] 非同步程式設計
      • [JS]原型繼承鏈模型
      • [Code] 格式化民國年
      • [Code] 複製元件內的文字
      • [DIY] 前端路由
      • [DIY] 開發 proxy
    • [前端] Typescript
      • [TS] 擴充標準內建物件
    • [前端] Vue
      • [Router] Navigation Guard 加入查詢參數
      • [TS] TS-Provide
      • [元件] CheckBox
      • [元件] Promise 元件方法
      • [元件] Transparent Wrapper
      • [元件] TypeScript 注意事項
      • [元件] 全域元件
    • [後端] .NET
      • [.NET] .NET 6 Web API 專案
      • [.NET] PDF 列印
      • [.NET] WebView2 單檔部屬
      • [.NET] 製作 Nuget package
      • [.NET] 開發階段專案敏感資料
      • [Snippet] DataTable轉Json
      • [Snippet] JsonElement 操作
      • [部屬手動] Ubuntu Nginx
      • [基礎] 非同步控制器
      • [練習] 認證與授權
        • [驗證與授權] 驗證與授權
        • [驗證與授權] 驗證設定
        • [驗證與授權] 驗證實例
        • [驗證與授權] 授權設定
        • [驗證與授權] 備註頁面
      • [練習] 即時聊天專案
        • [SignalR] 建立專案
        • [SignalR] 後端 Token 授權
        • [SignalR] 前端登入頁面
        • [SignalR] 後端 Token 認證
    • [後端] csharp
      • [Code] 處理民國年
      • [Code] 處理民國年
    • [系統] 軟體設計
      • [架構] 多層(layer)架構
      • [架構] 多層(tier)架構
      • [架構] 無暇的程式碼
      • [程式] 巢狀結構
      • [程設] 鏈式語法比較
    • [維運] Container 容器
      • [Basic] 學習資源
      • [Docker] 基礎指令
      • [Docker] 安裝
      • [K8s] 共享 tnsnames.ora
      • [K8S] 自架 K8S 腳本
    • [維運] DevOps
      • [Git] orphan branch/worktree
      • [Git] Release Action (Dotnet)
      • [Git] Release Action (Vue)
      • [K8S] K8S 安裝
      • [SonarQube] 安裝與.NET 檢測
    • [HIS] FHIR
      • [SMART] Overview
    • [其他] Other
      • [智能家居] Home Assistant
        • [安裝] Home Assistant 安裝
      • [Bot] Telegram Bot
      • [DIY] 一鍵登入台灣杉
      • [Hugo] Toha Theme
      • [OpenWrt] Docker
      • [工具] Gdrive CLI / Linux
      • [工具] openapi generator
      • [工具] Vim Plugin YCM
      • [授權] OAuth2.0
    Hero Image
    [元件] 把 attr、event、slot,直接 Passthrough 給子元件,製作包裝元件

    用來複寫給專案用的元件,用於在既有 UI framework 上打造專案元件 Vue3 Vue2.6 <template> <q-btn v-bind="{ ...$attrs, ...$props }" v-on="$listeners"> <template v-for="(_, slot) of $scopedSlots" v-slot:[slot]="scope"> <slot :name="slot" v-bind="scope"/> </template> <slot></slot> </q-btn> </template> Vue3 Vue3 裡面只要綁定 $attrs 即可,attrs, props, event 全部自動綁定進去。 <template> <q-btn v-bind="$attrs"> <template v-for="(slot, index) of Object.keys($slots)" :key="index" v-slot:[slot]> <slot :name="slot"></slot> </template> <slot></slot> </q-btn> </template> Quasar2-TS Quasar 裡面 Props, Slot 有獨立的 interface 定義,因此可直接拿到。 <template> <q-btn v-bind="$attrs"> <template v-for="(slot, index) of Object.keys($slots)" :key="index" v-slot:[slot]> <slot :name="slot"></slot> </template> </q-btn> </template> <script setup lang="ts"> import type { QBtnSlots, QBtnProps } from 'quasar'; import { QBtn } from 'quasar'; const props = withDefaults(defineProps<QBtnProps>(),{ // here comes default settings }); </script> <style scoped></style> Vuetify3 Vuetify3 裡面 Props, Slot 沒有獨立的 interface 定義,因此需額外定義。 MyBtn.

    April 6, 2023 Read
    Hero Image
    [But] TypeScript 注意事項

    用這樣的寫法,會造成 IDE 異常 :columns="columns as QTableProps['columns']"

    March 10, 2023 Read
    Hero Image
    [元件] 全域元件

    Vue 的作法 app.component('component-name', component) Quasar2 的做法 Vite/Typescript 建立 src/boot/register-my-component.ts import { boot } from 'quasar/wrappers'; import BasicBtnVue from 'src/components/BasicBtn.vue'; // "async" is optional; // more info on params: https://v2.quasar.dev/quasar-cli/boot-files export default boot(async ({ app }) => { app.component('x-btn', BasicBtnVue); }); 在 quasar.conf.js 內新增設定 module.exports = configure(function (/* ctx */) { return { // ...上略 // https://v2.quasar.dev/quasar-cli-vite/boot-files boot: ['i18n', 'register-my-component'], // ... 下略 }; }); 建立型別定義檔,我放在 src/components 下 components.d.ts import BasicBtn from '.

    December 13, 2022 Read
    Hero Image
    [Typescript] Typescript 用 InjectionKey 達成強型別 provide

    Working with Reactivity 上游元件 <script lang="ts"> import { InjectionKey, provide, Ref, reactive } from 'vue'; // State export interface IState { drawer: boolean; } export const stateKey: InjectionKey<Ref<IState>> = Symbol(); const state = reactive<IState>({ drawer: false, }); provide<IState>(stateKey, computed(()=>state)); </script> 下游元件 <script setup lang="ts"> import { inject, ref } from 'vue'; import { stateKey } from './Parent.vue'; const state = inject(stateKey, ref({ drawer: false })); </script> Reference Vue.js/guild - Provide / Inject Vue.

    November 17, 2022 Read
    Hero Image
    [DIY] 設計一個可回傳 Promise 的 Dialog 元件方法

    有用過 sweetalert2 的話,應該會喜歡可以同步等待對話框回傳值的方式, 這裡做一個 Vue2 元件,呼叫該元件的方法會彈出對話框等待使用者輸入,並且回傳 Promise, 如此一來就能夠在同一個函式當中處理使用者輸入值。 Dialog 元件設計原理: 元件方法 GetConfirm() 顯示 Dialog 元件並回傳一個 Promise,。 設置watcher讓元件取得使用者輸入後 resolve promise 得利於上述元件的設計,實際上的效益是將複雜度封裝到子元件裡面(watcher移動到元件內), 如此不需在上層元件撰寫使用者輸入取值的監視邏輯, 讓我們得以在上層元件直接 await GetConfirm 同步取得值進行操作。 這個概念的用途非常廣,例如 Vue router 的 component route guard,在離開表單頁面前跳出使用者確認的 Dialog。 Vue3 實作 <template> <v-dialog v-model="dialog" v-bind="$attrs"> <slot v-bind="{ Resolve }"></slot> </v-dialog> </template> <script setup> import { ref } from "vue"; const dialog = ref(false); let resolve = null; const Resolve = (v) => { resolve(v); dialog.value = false; }; const GetResult = async () => { dialog.

    August 26, 2022 Read
    Hero Image
    [DIY] Vue Router 使用 Navigation Guard 加入查詢參數

    工作上需要把每一個路由都加上同一個 query string 第一直覺就是直接寫成這樣: router.beforeEach(async (to, from, next) => { next({ path: path, query: {...to.queryl ,token: tokenStr} }) }) 結果卻跳出 Maximum call stack size exceeded 的錯誤,判斷程式出現無窮迴圈: runtime.js?96cf:285 Uncaught (in promise) RangeError: Maximum call stack size exceeded 第一個反應是傻眼貓咪,為什麼 next() 不傳入參數的時候不會出現無窮迴圈,但塞進參數就會, 難道說 next() 在傳入參數與不傳入參數的行為並不相同!! 因此去翻閱官網對 next() 的說明: next: Function: this function must be called to resolve the hook. The action depends on the arguments provided to next: next(): move on to the next hook in the pipeline.

    August 19, 2021 Read
    Hero Image
    [DIY] 用 Render Function 打造靈活的 CheckBox 元件範例

    情境1:要選取多個 ckeckbox 對應到資料庫的欄位,欄位值是一串YN代表某個選項是否有被選去,例如: YNNYYNNYYN 情境2:要選取多個 ckeckbox 對應到資料庫的欄位,欄位值只有一個,可能是任何字元,例如: 1 可以打造兩個元件,分別對應至單選、多選 單選元件 程式碼 (Code) Vue.component('x-ck-single', { props: { disabled: { type: Boolean, default: () => false }, // checkbox 的標記 [string] || [{text:string, value:any}] labels: { type: Array, default: () => ['Yes', 'No'] }, value: { default: () => null }, trueValue: { default: () => 'Y' }, falseValue: { default: () => 'N' }, inline: { type: Boolean, default: () => false }, }, data() { return { innervalue_: this.

    July 29, 2021 Read
    Navigation
    • About
    • Skills
    • Experiences
    • Education
    Contact me:
    • [email protected]
    • +886919681059

    Stay up to date with email notification


    By entering your email address, you agree to receive the newsletter of this website.

    Toha Theme Logo Toha
    © 2022 Copyright.
    Powered by Hugo Logo