unisave Documentation

website·Indexed 31 days ago

https://blog.sunpm.me

An open-source template based on Vue 3 and uni-app for creating type-safe, high-performance, and production-grade cross-platform applications. The documentation covers installation, state management with Pinia, data fetching using @uni-helper/uni-network, styling with UnoCSS, and UI component library integration.

Tokens
16.8K
Snippets
93
Records
121
Agent score
51%

What's inside unisave

  1. Overview of unisave template

    unisave is an open-source template based on Vue 3 and uni-app designed for creating type-safe, high-performance, and production-ready cross-platform applications. It allows developers to start writing .vue files immediately without manual configuration, drawing inspiration from the vitesse template. It focuses on embracing the open npm ecosystem and tools like VS Code and pnpm over proprietary environments.
  2. Pronounce the /i/ vowel sound

    To produce the /i/ sound, follow these mouth positioning steps:

    1. Smile (stretch the lips wide).
    2. Position the tongue as if there is a piece of candy under it, with the tip of the tongue touching the back of the lower teeth.
    3. Pull the corners of the mouth outwards to the sides.
  3. Prevent jitter in uni-app scroll-view using a debounce function

    When binding the @scroll event to update scrollTop in a uni-app scroll-view, the high frequency of function calls can cause page jitter. Implementing a debounce function ensures that the update logic only executes after a specified period of inactivity, reducing the number of DOM updates.
    // Debounce utility function
    function debounce(func, wait = 500) {
      if (timeout !== null) clearTimeout(timeout);
      timeout = setTimeout(() => {
        typeof func === 'function' && func();
      }, wait);
    }
    
    // Vue component implementation
    <template>
      <scroll-view :scroll-top="scrollTop" @scroll="scroll">
        <view>Content</view>
      </scroll-view>
    </template>
    
    <script>
    export default {
      data() {
        return {
          scrollTop: 0,
        }
      },
      methods: {
        scroll(e) {
          // Use bind to maintain 'this' context and pass the event object
          debounce(this.updateScrollTop.bind(this, e));
        },
        updateScrollTop(e) {
          this.scrollTop = e.detail.scrollTop;
        },
        goTop() {
          this.scrollTop = 0;
        }
      }
    }
    </script>
  4. Improve pronunciation using the Shadowing and Recording technique

    To develop an intuitive sense of pronunciation and rhythm, use the following active practice methods:

    1. Shadowing (The 'Shadow' Method): Listen to audio material and follow the speaker with a delay of exactly one word. When the speaker says the second word, you say the first. This provides real-time feedback on pronunciation and intonation gaps.
    2. Recording and Comparison: Use a phone or recorder to capture your speech. Repeat the same sentence multiple times, listen to the recording, and compare it against the original audio to identify specific errors.
    3. Physical Aids: Use a mirror to check mouth opening and a pen/chopstick to help fix the tongue position (e.g., lightly biting a pen for /θ/).
  5. Implement state management with Pinia and Persistence in Unisave

    Unisave uses Pinia for type-safe state management and pinia-plugin-persist-uni to handle data persistence specifically for uniapp environments. State is managed using the Composition API approach.
    import { defineStore } from 'pinia'
    import { ref } from 'vue'
    
    export const useCountStore = defineStore('count', () => {
      const count = ref(0)
    
      function inc() {
        count.value += 1
      }
      function dec() {
        count.value -= 1
      }
    
      return {
        count,
        inc,
        dec,
      }
    }, {
      persist: {
        enabled: true,
        detached: true, // Detach subscription from component
      },
    })
    
  6. Add ESLint configuration to an existing Vue CLI project

    To add ESLint to a Vue CLI project, use the vue add command. During the installation process, you will be prompted to select a configuration style (e.g., Prettier, Airbnb, Standard) and additional linting features such as 'Lint on save'. Once configured, the CLI automatically installs the necessary dependencies, creates the configuration files, and formats the existing project code.
    vue add @vue/eslint
  7. Extract function parameter and return types using Parameters and ReturnType

    When a function is imported from a module (or a third-party library) but its parameter and return types are not explicitly exported, you can use the Parameters<T> and ReturnType<T> utility types to derive them.

    Because these utility types expect a function type rather than the function implementation itself, you must use the typeof operator to get the type of the function.

    • Parameters<typeof func> returns a tuple containing all the parameter types of the function. To get a specific parameter, access it via an index (e.g., [0] for the first parameter).
    • ReturnType<typeof func> returns the type of the value returned by the function.
    // Example function where types are NOT exported
    export function login(param: { username: string; password: string }) {
      return { token: 'token' };
    }
    
    // --- In another file ---
    import { login } from './login';
    
    // 1. Extract the type of the first parameter
    const userInfo: Parameters<typeof login>[0] = {
      username: 'admin',
      password: '123'
    };
    
    // 2. Extract the return type of the function
    const userResult: ReturnType<typeof login> = login(userInfo);
  8. Implement custom image upload logic in @toast-ui/editor

    By default, @toast-ui/editor handles image uploads (via popup, drag-and-drop, or clipboard paste) as Base64 strings. To implement a custom upload server logic, remove the default addImageBlobHook event handler and add a new listener that processes the image blob and returns the resulting URL via the callback.
    this.editor.eventEmitter.removeEventHandler('addImageBlobHook') // Remove default listener
    
    // Add custom upload logic
    this.editor.eventEmitter.listen('addImageBlobHook', (blob, callback) => {
      // Replace this.upload with your actual upload function
      this.upload(blob, (url) => {
        callback(url)
      })
    })
  9. Pronounce the English vowel sound /e/

    To produce the /e/ sound, follow these articulation steps:

    1. Slightly open the lips to the sides, leaving a gap between the upper and lower teeth approximately the width of a fingertip.
    2. Raise the front of the tongue during pronunciation, with the tip of the tongue slightly touching the back of the lower teeth.
    3. Gradually move the chin downward while vibrating the vocal cords to emit the /e/ sound.
  10. Train English consonants using group-specific methods

    Consonants should be tackled in groups using specific physical tests to ensure correct articulation:

    GroupKey SymbolsTraining Tool/Method
    Plosives/p/ /b/ /t/ /d/ /k/ /g/Tissue Test: Hold a tissue in front of the mouth; it should move when pronouncing /p/.
    Fricatives/f/ /v/ /θ/ /ð/ /s/ /z/Tongue Feel: For /θ/, the tip of the tongue must be between the teeth.
    Affricates/tʃ/ /dʒ/ /tr/ /dr/Contrast: Compare the tongue position of the Chinese sound "chi" with /tʃ/.
    Nasals/m/ /n/ /ŋ/Nose Pinch: Pinch the nose while pronouncing /m/; the sound should be blocked.
  11. Install and configure Wot Design Uni in a unisave project

    Wot Design Uni uses easycom for automatic component registration, eliminating the need for manual imports and registration in every page.
    pnpm add wot-design-uni

    Configure easycom

    Update pages.config.ts. Note: If you have other easycom rules, merge them into a single easycom field.

    {
      "easycom": {
        "autoscan": true,
        "custom": {
          "^wd-(.*)": "wot-design-uni/components/wd-$1/wd-$1.vue"
        }
      },
      "pages": [ ... ]
    }

    Type Support

    Update tsconfig.json to include global component types:

    {
      "compilerOptions": {
        "types": ["wot-design-uni/global"]
      }
    }
  12. Pronounce the English vowel sound /ɪ/

    To produce the /ɪ/ sound, follow these physical articulation steps:

    1. Open the mouth slightly with relaxed lips; the gap between the upper and lower teeth should be approximately the width of a fingertip.
    2. Place the tip of the tongue against the lower teeth. The hard palate of the tongue should be raised, but the overall tongue position is slightly low and shifted back, with the tongue muscles remaining relaxed.
    3. Stretch the lips slightly to the sides and vibrate the vocal cords to produce the sound.