vue-2-notes
Skill2 starsChanged 6 days agoMITView on GitHub
Vue 2 (^2.5.17, Options API era) component structure and the reactivity caveats that bite when mutating reactive state. Use when writing or reviewing .vue single-file components in a Vue 2 project (resources/assets/js), or a codebase whose package.json pins vue ^2.5.x. Covers the data() / computed / methods / watch + lifecycle shape, props-down + $emit events-up, vue-loader SFC compilation, the Vue.set / array-mutation traps, and @vue/test-utils 1.x + vue-jest 3 testing. Not for Vue 3 or 2.7 Composition API (predates setup() / <script setup>) — load when touching components or planning a Vue 2 → 3 migration. Output: Vue 2 component guidance, migration traps, and verification gates.
In this repository39 other files it gives its agents.
- AGENTS.mdAGENTS.md
- change-verdictSkill
- code-simplifySkill
- code-traceSkill
- create-prSkill
- deploy-listSkill
- doc-maintainSkill
- feature-verifySkill
- flow-driveSkill
- flow-guideSkill
- git-smart-commitSkill
- git-worktreeSkill
- harness-setupSkill
- issue-analyzeSkill
- js-static-checksSkill
- laravelSkill
- legacy-characterization-testsSkill
- library-authorSkill
- merge-prepSkill
- module-designSkill
- nextjsSkill
- openspec-artifact-guardSkill
- opsx-apply-resumeSkill
- phpSkill
- phpunitSkill
- precommitSkill
- project-auditSkill
- project-briefSkill
- proposal-analyzeSkill
- pr-summarySkill
- pythonSkill
- reactSkill
- release-creatorSkill
- repo-intakeSkill
- repo-verifySkill
- swiftSkill
- tdd-workflowSkill
- ui-ux-verifySkill
- yii1Skill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 193
If reviewing this codebase, these are absent — do not reach for them:
- Very specific: line 215
Not for Vue 3 or the 2.7 Composition API — this baseline predates setup() / <script setup>, so ref / reactive / composables do not exist.
- Very specific: line 230
No prop mutated in place; no this.obj.newKey =, this.arr[i] =, or this.arr.length = on reactive state.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Vue 2 — Options API baseline
Targets vue ^2.5.17. Options API only — the Composition API
(setup(), ref, reactive, <script setup>) does not exist here;
it arrives in 2.7 as a backport and is the default in Vue 3.
SFCs (
.vue) are compiled byvue-loaderdriven by Laravel Mix (webpack 4). Source lives underresources/assets/js. See thelaravelfamily skill'smixselector for the build wiring.
Signature features
Options API component structure
export default {
name: 'OrderTicket',
props: {
order: { type: Object, required: true },
compact: { type: Boolean, default: false },
},
// data MUST be a function returning a fresh object, so each
// component instance gets its own state (not a shared reference).
data() {
return {
expanded: false,
note: '',
};
},
computed: {
// cached, re-evaluated only when a reactive dependency changes
title() {
return this.compact ? this.order.no : this.order.fullName;
},
},
methods: {
toggle() {
this.expanded = !this.expanded;
},
},
watch: {
// imperative side effects on a value change
'order.status'(next, prev) {
if (next === '6') this.$emit('done', this.order.id);
},
},
created() {
// instance + reactivity ready; DOM NOT yet mounted
},
mounted() {
// DOM available; safe to read $refs / attach listeners
},
};Lifecycle order: beforeCreate → created → beforeMount → mounted →
beforeUpdate → updated → beforeDestroy → destroyed. Fetch data in
created (no DOM needed); touch the DOM in mounted.
Props down, events up
State flows one direction. A child never mutates a prop; it emits an event and lets the owner of the state change it.
// child
methods: {
remove() {
this.$emit('remove', this.item.id); // ask parent to mutate
},
},<!-- parent template -->
<order-item
:item="item"
@remove="onRemove"
/>Mutating a prop in place triggers a Vue warning and is overwritten on the next parent re-render.
Single-file components
<template> + <script> + <style> in one .vue file, compiled by
vue-loader. The template compiles to a render function at build time
(not at runtime), so the runtime-only Vue build is enough.
Reactivity caveats (the classic Vue 2 traps)
Vue 2 reactivity is built on Object.defineProperty, which can only
observe properties that exist when the component is created. Three
mutations silently fail to trigger re-renders:
1. Adding a new property to a reactive object
// NOT reactive — the view will not update
this.order.discount = 10;
// reactive
this.$set(this.order, 'discount', 10);
// or, outside a component:
Vue.set(this.order, 'discount', 10);Declare every key you intend to mutate up front in data() (even as
null) to avoid needing $set at all.
2. Array index assignment
// NOT reactive
this.items[0] = newItem;
// reactive
this.$set(this.items, 0, newItem);
// or
this.items.splice(0, 1, newItem);3. Array length mutation
// NOT reactive
this.items.length = 0;
// reactive — splice is observed
this.items.splice(0);The array methods Vue patches and observes: push, pop, shift,
unshift, splice, sort, reverse. Index/length writes are not
among them.
Testing
@vue/test-utils 1.x (the line that targets Vue 2) + vue-jest
3 to compile SFCs under Jest with the jsdom environment.
import { shallowMount } from '@vue/test-utils';
import OrderTicket from '@/components/OrderTicket.vue';
describe('OrderTicket', () => {
it('emits done when status reaches 6', async () => {
const wrapper = shallowMount(OrderTicket, {
propsData: { order: { id: 7, status: '5', no: 'A1' } },
});
wrapper.setProps({ order: { id: 7, status: '6', no: 'A1' } });
await wrapper.vm.$nextTick();
expect(wrapper.emitted('done')[0]).toEqual([7]);
});
});mountrenders child components;shallowMountstubs them (faster, isolates the unit).- State changes are async —
await wrapper.vm.$nextTick()(orawait wrapper.setProps(...)) before asserting on rendered output. - jsdom env in
jest.config.js:testEnvironment: 'jsdom'.
What's missing compared to 2.7 / Vue 3
If reviewing this codebase, these are absent — do not reach for them:
- No Composition API — no
setup(),ref,reactive,computedas standalone imports. Logic reuse is via mixins or render-prop / scoped-slot patterns, not composables. - No
<script setup>— every component is an exported options object. - No Teleport, no Fragments — a component template requires a
single root element; multiple sibling roots are a compile error.
Wrap in one
<div>. v-modelbindsvalue+inputonly (no namedv-model/ multiple models — that is Vue 3).
Migration awareness: a 2 → 3 move means rewriting Vue.set calls
(reactivity is Proxy-based in 3, so the traps above largely disappear),
relaxing the single-root rule, and converting global API calls
(new Vue() → createApp).
When NOT to Use
Not for Vue 3 or the 2.7 Composition API — this baseline predates setup() /
<script setup>, so ref / reactive / composables do not exist. Not for the
build pipeline (see the laravel family skill's mix selector) or non-.vue JS (see
js-static-checks). Load when touching .vue SFCs in a vue ^2.5.x
codebase, or planning a 2 → 3 migration.
Output
Options-API .vue components with data() as a function, props-down /
$emit-up data flow, reactive mutations via $set / splice (never index or
length assignment), a single root element, and @vue/test-utils 1.x +
vue-jest 3 specs that await $nextTick() before asserting.
Verification
- No prop mutated in place; no
this.obj.newKey =,this.arr[i] =, orthis.arr.length =on reactive state. - Each component template has exactly one root element.
- Tests use
shallowMount/mountfrom@vue/test-utils1.x under thejsdomenv andawaita tick before reading emitted / rendered output.
Cross-references
skills/laravel/SKILL.md(mixselector) — the webpack build that compiles these.vueSFCs and maps them topublic/skills/js-static-checks/SKILL.md— ESLint / TypeScript tier strategy that governs the.vueand.jssources
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

