
more 注释之前的内容被视为文章摘要。
2020/1/1大约 2 分钟

more 注释之前的内容被视为文章摘要。
icon: akar-icons:file
date: 2026-02-04
order: 2
category:
vite 插件的本质就上 rollup插件 + vite 独有的钩子
┌─────────────────────────────────────────────────────┐
│ Vite 插件 │
├─────────────────────────────────────────────────────┤
│ Rollup 插件钩子 (通用) │
│ ├── buildStart │
│ ├── resolveId │
│ ├── load │
│ ├── transform │
│ ├── renderChunk │
│ ├── generateBundle │
│ └── writeBundle │
├─────────────────────────────────────────────────────┤
│ Vite 独有钩子 │
│ ├── config │
│ ├── configResolved │
│ ├── configureServer │
│ ├── transformIndexHtml │
│ └── handleHotUpdate │
└─────────────────────────────────────────────────────┘
JavaScript 是一门单线程、非阻塞的语言。事件循环(Event Loop)是 JavaScript 实现异步编程的核心机制,它负责协调主线程执行同步代码和管理异步任务的执行顺序。
JavaScript 只有一个主线程,同步代码会阻塞主线程。事件循环的作用是在主线程空闲时,从任务队列中取出任务执行,从而实现「非阻塞」的特性。
执行栈是一个后进先出(LIFO)的数据结构,用于存储代码执行时的上下文。
在进行类型判断的时候 typeof 是最常用的工具之一,但它并非没有问题
Api 用法
// 原始类型
console.log(typeof 'hello'); // "string"
console.log(typeof 123); // "number"
console.log(typeof true); // "boolean"
console.log(typeof Symbol('id')); // "symbol"
console.log(typeof 123n); // "bigint"
console.log(typeof undefined); // "undefined"
// 对象类型
console.log(typeof { a: 1 }); // "object"
console.log(typeof [1, 2, 3]); // "object" (陷阱)
console.log(typeof new Date()); // "object"
// 函数
console.log(typeof function() {});// "function" (特殊的对象)
import { createRouter, createWebHistory } from 'vue-router'
import NotFound from '@/views/NotFound.vue'
const router = createRouter({
history: createWebHistory(),
routes: [
// 其他路由...
{ path: '/', component: Home },
{ path: '/about', component: About },
// 404 路由配置 - 放在最后
{ path: '/:pathMatch(.*)*', name: 'NotFound', component: NotFound }
]
})
import GUI from "lil-gui";
const gui = new GUI();
const eventObj = {
fullScreen: () => {
document.body.requestFullscreen();
},
size: 0,
};
gui.add(eventObj, "fullScreen").name("全屏");
gui.add(cube.position, "x").min(-10).max(10).step(0.1).name("立方体位置 x");
gui
.add(eventObj, "size")
.min(0)
.max(100)
.step(1)
.name("立方体大小")
.onChange((value) => {
cube.scale.set(value, value, value);
});
import * as THREE from "three";
const scene = new THREE.Scene();
// 创建一个透视相机 第一个参数是视野范围 第二个参数是宽高比 第三个参数是近裁剪面 第四个参数是远裁剪面
const camera = new THREE.PerspectiveCamera(
75,
window.innerWidth / window.innerHeight,
0.1,
1000,
);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
renderer.render(scene, camera);
每个物品放入场景的时候都需要一个mesh(网格),mesh是一个物体的基本单位,每个mesh都有一个position属性,position属性是一个Vector3对象,用来表示物体的位置。
position属性有三个属性x、y、z,分别表示物体在三个轴上的位置。
// 设置物体位置
mesh.position.set(1, 2, 3);
export default defineConfig({
build: {
minify: "terser",
terserOptions: {
compress: {
drop_console: false, // 不自动移除所有 console
pure_funcs: ["console.log", "console.info", "console.debug"], // 只移除指定的
drop_debugger: true,
},
},
},
});
在这里就以一个用户表和抽奖次数表为例 一个用户拥有多少次抽奖机会 就是一对一的关系
import {Column, Entity, ManyToOne, PrimaryGeneratedColumn, JoinColumn, OneToMany, OneToOne} from 'typeorm'
import {RoleEntity} from '@entity/role.entity'
import {LotteryRecordEntity} from '@entity/lotteryRecord.entity'
import {LotteryChancesEntity} from '@entity/lotteryChances.entity'
@Entity({name: 'user'})
export class UserEntity {
@PrimaryGeneratedColumn({type: 'int'})
id: number
@Column({type: 'varchar', length: 255, nullable: false})
name: string
@Column({nullable: true, default: 'man'})
gender: string
@Column({nullable: true, default: 0})
age: number
@Column({nullable: false, unique: true, type: 'bigint'})
phone: string
@Column({nullable: true})
description: string
@Column({nullable: true, type: 'datetime', name: 'create_time'})
createTime: Date
@Column({type: 'varchar', length: 255, nullable: false})
password: string
// many users can have one role. explicit inverse and join column (role_id)
@ManyToOne(() => RoleEntity, role => role.users, {nullable: true})
@JoinColumn({name: 'role_id'})
role: RoleEntity | null
// @OneToMany(() => LotteryRecordEntity, lotteryRecord => lotteryRecord.user)
// lotteryRecords: LotteryRecordEntity[]
@OneToOne(() => LotteryChancesEntity, lotteryChances => lotteryChances.user)
lotteryChances: LotteryChancesEntity
}