安装
npm i nanoid
使用
import {nanoid} from 'nanoid' export default { name:"School", data() { return { name:"xiao bai", adress:"北京", id:nanoid(5) } }, }
<template> <div class="school"> <h2> 学校名称 {{name}}</h2> <h2> 学校地址 {{adress}}</h2> <h2> id {{id}}</h2> </div> </template>
这样就可以在你的页面生成随机id了