1. rective 创建一个响应式对象
2. ref 和 reactive
- vue 使用 proxy API创建响应式,但是 proxy 只能代理对象。
- ref 使用 defined
- reactive 使用 proxy
- ref 实际调用了 reactive API
此时产生的问题:
- reactive 性能更好,应该推荐用户使用 reactive。
- ref 实际调用 reactive,是不是代表:只需要 ref
2025/11/30小于 1 分钟
// useCount.ts
import { ref, watch } from 'vue'
const count = ref(0)
const doubleCount = ref(0)
function handleChangeCount() {
count.value++
}
watch(count, () => {
doubleCount.value = count.value * 2
})
export function useCounter() {
return {
count,
handleChangeCount,
doubleCount,
}
}
本文档用于说明上述三个包的关系、差异以及推荐的使用方式。
轻量级、模块化的 JavaScript 日期处理库,提供格式化、解析、计算等基础操作。
不包含任何时区处理能力。
示例:
import { format, addDays } from "date-fns";
format(new Date(), "yyyy-MM-dd");
addDays(new Date(), 7);
<template>
<div>{{ num }}</div>
</template>
<script setup>
import { ref } from 'vue'
const num = ref(0)
</script>
// api.ts
import apiRequset form 'request.ts'
// 用户管理
export async function getList(data: {
page: number;
pageSize: number;
}) {
const token = await getToken();
return await apiRequest<PageData<Platform>>({
url: "api/list",
method: "POST",
data,
token,
});
}
// view
const requestParams = {
page: 1,
pageSize: 10
}
const { data } = await getList(requestParams);
两种方式
npm create vue@latest
实际区别(Vite 官方逻辑):
assets/public//xxx.png最基本的数据绑定形式是文本插值,它使用的是“Mustache”语法 (即双大括号)
<template>
<div>{{ name }}</div>
</template>
<script setup>
const name = "lorem";
</script>
const nextConfig: NextConfig = {
output: "standalone",
}