The usage of NanoID with randomly generated id

foreword

In the use of the framework, id is needed in many places. And NanoID is a plugin that generates a unique ID. This section will introduce the usage of the plugin.

introduce

NanoID, like UUID, is one of the most commonly used universal identifiers in software development.

However, compared with UUID, NanoID is lighter, safer, faster and more compact, and has good compatibility and no third-party dependencies. It is a very mainstream plug-in for generating identification.

usage

Open the terminal and use the npm package management tool to download:

npm i nanoid

Introduce this method:

import {
    
    nanoid} from 'nanoid'

Finally, you can use, for example, to generate a random id:

 const personObj = {
    
    
       name: this.name,
       id: nanoid()
}

Effect

insert image description here

Guess you like

Origin blog.csdn.net/zxdznyy/article/details/128881442