Skills2026年4月13日·1 分钟阅读

Vue.js — The Progressive JavaScript Framework

Vue.js is a progressive framework for building user interfaces. It features an approachable core with an incrementally adoptable ecosystem — from simple script includes to full-featured SPA development with Composition API, reactivity, and single-file components.

Agent 就绪

先审查再安装

这个资产需要先审查。复制的指令会要求 Agent dry-run、列出写入项,确认后再继续。

Needs Confirmation · 64/100策略:需确认
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
step-1.md
先审查命令
npx -y tokrepo@latest install 6935d236-3702-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run,确认写入项后再运行此命令。

TL;DR
Vue.js offers an approachable core with incremental adoption from simple widgets to full-scale SPAs.
§01

What it is

Vue.js is a progressive JavaScript framework for building user interfaces. It provides a reactive data binding system, component architecture, and a rich ecosystem including Vue Router for navigation and Pinia for state management. Vue can be used as a lightweight library for enhancing static pages or as a full framework for single-page applications.

Vue targets frontend developers at all skill levels. Its gentle learning curve makes it accessible to beginners, while its Composition API and TypeScript support satisfy the needs of large-scale application development.

§02

How it saves time or tokens

Vue's single-file component format (.vue files) co-locates template, script, and style in one file, reducing context switching during development. The Composition API enables logic reuse through composable functions, eliminating the need to restructure components when sharing behavior.

The Vue CLI and Vite-based scaffolding tool (create-vue) set up a production-ready project with routing, state management, and build optimization in a single command. This eliminates hours of boilerplate configuration.

§03

How to use

  1. Create a new Vue project:
npm create vue@latest my-app
cd my-app
npm install
npm run dev
  1. Edit src/App.vue to build your interface:
<script setup>
import { ref } from 'vue'
const count = ref(0)
</script>

<template>
  <button @click="count++">Count: {{ count }}</button>
</template>
  1. Build for production:
npm run build
§04

Example

<script setup lang="ts">
import { ref, computed } from 'vue'

interface Todo {
  id: number
  text: string
  done: boolean
}

const todos = ref<Todo[]>([
  { id: 1, text: 'Learn Vue 3', done: false },
  { id: 2, text: 'Build an app', done: false }
])

const remaining = computed(() =>
  todos.value.filter(t => !t.done).length
)

function toggle(todo: Todo) {
  todo.done = !todo.done
}
</script>

<template>
  <h2>Todos ({{ remaining }} remaining)</h2>
  <ul>
    <li v-for="todo in todos" :key="todo.id">
      <input type="checkbox" :checked="todo.done" @change="toggle(todo)" />
      {{ todo.text }}
    </li>
  </ul>
</template>

This demonstrates Vue's reactivity system, computed properties, list rendering, and TypeScript integration in a single-file component.

§05

Related on TokRepo

§06

Common pitfalls

  • Mixing Options API and Composition API in the same project creates inconsistency. Pick one style and apply it consistently. The Composition API with <script setup> is the recommended approach for new projects.
  • Vue's reactivity system tracks property access. Destructuring reactive objects loses reactivity. Use toRefs() when destructuring props or store state.
  • Large Vue applications need code splitting. Without lazy-loaded routes (defineAsyncComponent and dynamic imports), the initial bundle grows large and slows page load.

常见问题

What is the difference between Vue 2 and Vue 3?+

Vue 3 introduced the Composition API, improved reactivity with Proxy-based tracking, better TypeScript support, Teleport and Suspense components, and significant performance improvements. Vue 2 reached end of life in December 2023. New projects should use Vue 3.

How does Vue compare to React?+

Vue uses single-file components with templates by default, while React uses JSX. Vue provides built-in reactivity, transitions, and a router as official packages. React's ecosystem relies more on third-party libraries. Vue has a gentler learning curve; React has a larger ecosystem and job market.

Does Vue support server-side rendering?+

Yes. Nuxt is the official Vue framework for SSR. It provides file-based routing, auto-imports, SEO optimization, and hybrid rendering modes. For basic SSR without Nuxt, Vue provides the @vue/server-renderer package.

Can I use Vue with TypeScript?+

Yes. Vue 3 is written in TypeScript and provides first-class TypeScript support. The Composition API with <script setup lang='ts'> enables full type inference for props, events, slots, and composables. Volar is the recommended VS Code extension for Vue TypeScript support.

What state management should I use with Vue?+

Pinia is the officially recommended state management library for Vue 3. It replaced Vuex as the default choice. Pinia provides a simpler API, better TypeScript support, and devtools integration. For simple applications, Vue's built-in reactivity with provide/inject may be sufficient.

引用来源 (3)

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产