vue2

teachingai/full-stack-skills · updated May 22, 2026

MDX-style export adds YAML metadata + attribution linking explainx.ai and this canonical listing URL.

$npx skills add https://github.com/teachingai/full-stack-skills --skill vue2
0 commentsdiscussion
summary

本技能提供 Vue 2.x 框架的完整开发指南,包括 Options API、组件系统、路由管理、状态管理(Vuex)、生命周期等核心概念和最佳实践。

skill.md

Vue 2 开发指南

概述

本技能提供 Vue 2.x 框架的完整开发指南,包括 Options API、组件系统、路由管理、状态管理(Vuex)、生命周期等核心概念和最佳实践。

核心特性

1. Options API

Vue 2 使用 Options API 组织组件代码。

基本结构

<template>
  <div>
    <p>{{ message }}</p>
    <p>Count: {{ count }}</p>
    <button @click="increment">Increment</button>
  </div>
</template>

<script>
export default {
  name: 'Counter',
  data() {
    return {
      message: 'Hello Vue 2',
      count: 0
    }
  },
  computed: {
    doubleCount() {
      return this.count * 2
    }
  },
  watch: {
    count(newVal, oldVal) {
      console.log(`count changed from ${oldVal} to ${newVal}`)
    }
  },
  methods: {
    increment() {
      this.count++
    }
  },
  mounted() {
    console.log('Component mounted')
  }
}
</script>

2. 响应式数据

data:定义响应式数据

data() {
  return {
    message: 'Hello',
    count: 0,
    user: {
      name: 'Vue',
      age: 2
    }
  }
}

注意事项

  • 使用 this.$set 添加新属性
  • 使用 Vue.setthis.$set 修改数组索引

3. 计算属性和监听器

计算属性

computed: {
  fullName() {
    return `${this.firstName} ${this.lastName}`
  }
}

监听器

watch: {
  // 简单监听
  count(newVal, oldVal) {
    // ...
  },
  // 深度监听
  user: {
    handler(newVal, oldVal) {
      // ...
    },
    deep: true
  }
}

4. 组件开发

组件定义

<template>
  <div>
    <h3>{{ title }}</h3>
    <p>{{ content }}</p>
  </div>
</template>

<script>
export default {
  name: 'MyComponent',
  props: {
    title: {
      type: String,
      required: true
    },
    content: {
      type: String,
      default: ''
    }
  },
  emits: ['update', 'delete'],
  methods: {
    handleClick() {
      this.$emit('update', this.title)
    }
  }
}
</script>

组件通信

  • Props:父 → 子
  • $emit:子 → 父
  • $parent / $children:父子组件直接访问
  • $refs:访问子组件实例
  • Vuex:全局状态管理
  • EventBus:事件总线

5. 路由管理(Vue Router)

基本配置

import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: () => import('./views/Home.vue')
  },
  {
    path: '/about',
    component: () => import('./views/About.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  routes
})

路由使用

<template>
  <div>
    <router-link to="/about">About</router-link>
    <router-view />
  </div>
</template>

<script>
export default {
  methods: {
    goToAbout() {
      this.$router.push('/about')
    }
  },
  mounted() {
    console.log(this.$route.params)
  }
}
</script>

6. 状态管理(Vuex)

Store 定义

import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    count: 0
  },
  getters: {
    doubleCount: state => state.count * 2
  },
  mutations: {
    INCREMENT(state) {
      state.count++
    }
  },
  actions: {
    increment({ commit }) {
      commit('INCREMENT')
    }
  }
})

在组件中使用

<script>
import { mapState, mapGetters, mapActions } from 'vuex'

export default {
  computed: {
    ...mapState(['count']),
    ...mapGetters(['doubleCount'])
  },
  methods: {
    ...mapActions(['increment'])
  }
}
</script>

7. 生命周期钩子

export default {
  beforeCreate() {
    // 实例初始化之后,数据观测之前
  },
  created() {
    // 实例创建完成,数据观测完成
  },
  beforeMount() {
    // 挂载开始之前
  },
  mounted() {
    // 挂载完成
  },
  beforeUpdate() {
    // 数据更新时,DOM 更新之前
  },
  updated() {
    // DOM 更新完成
  },
  beforeDestroy() {
    // 实例销毁之前
  },
  destroyed() {
    // 实例销毁完成
  }
}

最佳实践

1. 代码组织

  • 使用单文件组件(.vue)
  • 合理拆分组件
  • 使用 mixins 复用逻辑

2. 性能优化

  • 使用 v-ifv-show 合理选择
  • 使用 key 优化列表渲染
  • 懒加载路由组件
  • 使用 Object.freeze() 冻结大对象

3. 组件通信

  • 优先使用 Props 和 Events
  • 复杂状态使用 Vuex
  • 避免过度使用 $parent$children

4. 响应式注意事项

// 添加新属性
this.$set(this.user, 'age', 25)

// 修改数组索引
this.$set(this.items, 0, newItem)

// 修改数组长度
this
how to use vue2

How to use vue2 on Cursor

AI-first code editor with Composer

1

Prerequisites

Before installing skills in Cursor, ensure your development environment meets these requirements:

  • Cursor installed and configured on your development machine
  • Node.js version 16.0+ with npm package manager (verify with node --version)
  • Active project directory or workspace where you want to add vue2
2

Execute installation command

Execute the skills CLI command in your project's root directory to begin installation:

$npx skills add https://github.com/teachingai/full-stack-skills --skill vue2

The skills CLI fetches vue2 from GitHub repository teachingai/full-stack-skills and configures it for Cursor.

3

Select Cursor when prompted

The CLI will show a list of available agents. Use arrow keys to navigate and space to select Cursor:

◆ Which agents do you want to install to?
│ ── Universal (.agents/skills) ── always included ────
│ • Amp
│ • Antigravity
│ • Cline
│ • Codex
│ ●Cursor(selected)
│ • Cursor
│ • Windsurf
4

Verify installation

Confirm successful installation by checking the skill directory location:

.cursor/skills/vue2

Reload or restart Cursor to activate vue2. Access the skill through slash commands (e.g., /vue2) or your agent's skill management interface.

Security & Verification Notice

We perform automated surface-level scans (Gen AI Scanner, Socket, Snyk) during installation. These checks detect common vulnerabilities but do not guarantee complete security. Always review skill source code and verify the publisher's reputation before production use.

Skills execute code in your development environment. Always verify the publisher's identity, review recent commits, and test in isolated environments before production deployment.

List & Monetize Your Skill

Submit your Claude Code skill and start earning

GET_STARTED →

Use Cases

Task Automation & Efficiency

Automate repetitive workflows and reduce manual effort

Example

Generate reports, summarize documents, draft communications

Save 3-5 hours per week on routine tasks

Knowledge Enhancement

Learn new skills, understand complex topics, get expert guidance

Example

Explain concepts, provide examples, suggest learning resources

Accelerate learning and skill development by 2x

Quality Improvement

Enhance output quality through reviews, suggestions, and refinements

Example

Review drafts, suggest improvements, catch errors

Improve work quality by 30-40% with less effort

Implementation Guide

Prerequisites

  • Claude Desktop or compatible AI client with skill support
  • Clear understanding of task or problem to solve
  • Willingness to iterate and refine outputs

Time Estimate

15-45 minutes depending on use case complexity

Installation Steps

  1. 1.Install skill using provided installation command
  2. 2.Test with simple use case relevant to your work
  3. 3.Evaluate output quality and relevance
  4. 4.Iterate on prompts to improve results
  5. 5.Integrate into regular workflow if valuable

Common Pitfalls

  • Expecting perfect results without iteration
  • Not providing enough context in prompts
  • Using skill for tasks outside its intended scope
  • Accepting outputs without review and validation

Best Practices

✓ Do

  • +Start with clear, specific prompts
  • +Provide relevant context and constraints
  • +Review and refine all outputs before using
  • +Iterate to improve output quality
  • +Document successful prompt patterns

✗ Don't

  • Don't use without understanding skill limitations
  • Don't skip validation of outputs
  • Don't share sensitive information in prompts
  • Don't expect skill to replace human judgment

💡 Pro Tips

  • Be specific about desired format and style
  • Ask for multiple options to choose from
  • Request explanations to understand reasoning
  • Combine AI efficiency with human expertise

When to Use This

✓ Use When

Use when skill capabilities match your task, clear ROI on time saved, and you can validate outputs. Best for repetitive tasks, learning, and quality improvement.

✗ Avoid When

Avoid when task requires deep expertise you can't validate, involves sensitive decisions, or when learning process is more valuable than speed of completion.

Learning Path

  1. 1Familiarize yourself with skill capabilities and limitations
  2. 2Start with low-risk, non-critical tasks
  3. 3Progress to more complex and valuable use cases
  4. 4Build expertise through regular use and experimentation

Discussion

Product Hunt–style comments (not star reviews)
  • No comments yet — start the thread.
general reviews

Ratings

4.559 reviews
  • Isabella Dixit· Dec 20, 2024

    I recommend vue2 for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.

  • Kwame Iyer· Dec 12, 2024

    Registry listing for vue2 matched our evaluation — installs cleanly and behaves as described in the markdown.

  • Benjamin Flores· Dec 8, 2024

    We added vue2 from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.

  • Daniel Wang· Dec 8, 2024

    Useful defaults in vue2 — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.

  • Dhruvi Jain· Dec 4, 2024

    Useful defaults in vue2 — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.

  • Zara Okafor· Dec 4, 2024

    vue2 fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.

  • Kabir Gill· Nov 27, 2024

    vue2 has been reliable in day-to-day use. Documentation quality is above average for community skills.

  • Oshnikdeep· Nov 23, 2024

    vue2 has been reliable in day-to-day use. Documentation quality is above average for community skills.

  • Benjamin Perez· Nov 11, 2024

    Solid pick for teams standardizing on skills: vue2 is focused, and the summary matches what you get after install.

  • Kiara Jackson· Nov 3, 2024

    Keeps context tight: vue2 is the kind of skill you can hand to a new teammate without a long onboarding doc.

showing 1-10 of 59

1 / 6