Vue VSCode Snippets

his repo was built particularly for real world use. It doesn't catalogue the API definitions, rather, it focuses on developer ergonomics from the point of Vue of real world use. Included are the pieces I personally get sick of typing, and boilerplate that is helpful to stub out quickly.

Versions Supported: Vue 2 and Vue 3

SnippetDemo

Installation

Either

  • click the extensions button (lowest square icon in the editor), and type in Vue VSCode Snippets, select the one by sdras

or

 

ext install Vue VSCode Snippets

You can enable tab completion (recommended) by opening Code > Preferences > Settings (on a Mac) and applying "editor.tabCompletion": "onlySnippets" to your personal settings

Snippets

Vue

SnippetPurpose
vbaseSingle file component base with SCSS
vbase-3Single File component Composition API with SCSS
vbase-3-setupSingle File component setup Composition API with SCSS
vbase-3-reactiveSingle File component Composition API with Reactive and SCSS
vbase-cssSingle file component base with CSS
vbase-pcssSingle file component base with PostCSS
vbase-stylSingle file component base with Stylus
vbase-tsSingle file component base with Typescript
vbase-ts-classSingle file component base with Typescript Class Format
vbase-3-tsSingle File component Composition API with Typescript
vbase-3-ts-setupSingle File component setup Composition API with Typescript
vbase-nsSingle file component with no styles
vbase-sassSingle file component base with SASS
vbase-lessSingle file component base with LESS

Template

SnippetPurpose
vforv-for directive
vmodelSemantic v-model directive
vmodel-numSemantic v-model number directive
vonv-on click handler with arguments
vslot-namedNamed slot
vel-propsComponent element with props
vsrcImage src binding
vstyleInline style binding
vstyle-objInline style binding with objects
vclassClass binding
vclass-objClass binding with objects
vclass-obj-multMultiple conditional class bindings
vanimTransition component with JS hooks
vnuxtlNuxt Routing Link
vroutenamerouter-link Named Routing
vroutenameparamrouter-link Named with Parameters
vroutepathrouter-link Path Routing Link
vemit-childEmit event from child component
vemit-parentEmit event to parent component

Script

SnippetPurpose
vdataComponent data as a function
vmethodVue method
vcomputedVue computed property
vwatcherVue watcher with new and old value args
vbeforecreatebeforeCreate lifecycle method
vcreatedcreated lifecycle method
vbeforemountbeforeMount lifecycle method
vmountedvmounted lifecycle method
vbeforeupdatebeforeUpdate lifecycle method
vupdatedupdated lifecycle method
vbeforedestroybeforeDestroy lifecycle method
vdestroyeddestroyed lifecycle method
vpropsProps with type and default
vimportImport one component into another
vimport-dynamicImport one component that should be lazy loaded by webpack
vcomponentsImport one component into another within the export statement
vimport-exportImport one component into another and use it within the export statement
vmapstateimport mapState from Vuex into vue component component
vmapgettersimport mapGetters from Vuex into vue component component
vmapmutationsimport mapMutations from Vuex into vue component component
vmapactionsimport mapActions from Vuex into vue component component
vfilterVue filter
vmixinCreate a Vue Mixin
vmixin-useBring a mixin into a component to use
vc-directVue create a custom directive
vimport-libImport a library
vimport-gsapImport GreenSock
vanimhook-jsUsing the Transition component JS hooks in methods
vcommitCommit to Vuex store in methods for mutation
vdispatchDispatch to Vuex store in methods for action
vtestA simple unit testing component

Vue Composition API

SnippetPurpose
v3reactiveVue Composition API - reactive
v3reactive-setupVue Composition API - reactive with setup boilerplate
v3computedVue Composition API - computed
v3watchVue Composition API - watcher single source
v3watch-arrayVue Composition API - watch as array
v3watcheffectVue Composition API - watchEffect
v3refVue Ref
v3onmountedLifecycle hook - onMounted
v3onbeforemountLifecycle hook - onBeforeMount
v3onbeforeupdateLifecycle hook - onBeforeUpdate
v3onupdatedLifecycle hook - onUpdated
v3onerrorcapturedLifecycle hook - onErrorCaptured
v3onunmountedLifecycle hook - (destroyed) onUnmounted
v3onbeforeunmountLifecycle hook - (beforeDestroy) onBeforeUnmount
v3useinoptionsUse Composition API in Options API

Vuex

SnippetPurpose
vstoreBase for Vuex store.js
vgetterVuex Getter
vmutationVuex Mutation
vactionVuex Action
vmoduleVuex Module
vstore-importImport vuex store into main.js
vstore2Updated Base for Vuex store

Vue Router

SnippetPurpose
vrouterVue Router base
vscrollbehaviorVue Router scrollBehavior
vbeforeeachVue Router global guards beforeEach
vbeforeresolveVue Router global guards beforeResolve
vaftereachVue Router global guards afterEach
vbeforeenterVue Router per-route guard beforeEnter
vbeforerouteenterVue Router component guards beforeRouteEnter
vbeforerouteupdateVue Router component guards beforeRouteUpdate
vbeforerouteleaveVue Router component guards beforeRouteLeave

Vue Config

SnippetPurpose
vpluginImport a plugin to main.js or plugins file
vconfigvue.config.js file, example imports a sass file into every component

Nuxt Config

SnippetPurpose
nfontlink to include fonts in a nuxt project, in nuxt-config
ncsslink to css assets such as normalize

Nuxt Page

SnippetPurpose
nasyncdataNuxt asyncData
nasyncdataaxiosNuxt asyncData with Axios module
nfetchNuxt Fetch
nfetchaxiosNuxt Fetch with Axios module
nheadNuxt Head
nparamNuxt Route Params
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AI周红伟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值