Git Product home page Git Product logo

sdras / vue-vscode-snippets Goto Github PK

View Code? Open in Web Editor NEW
1.3K 24.0 179.0 1.7 MB

These snippets were built to supercharge my workflow in the most seamless manner possible.

Home Page: https://marketplace.visualstudio.com/items?itemName=sdras.vue-vscode-snippets

License: MIT License

JavaScript 100.00%
vscode vscode-extension vscode-vue vue2 vuejs vuejs2 vue-snippets snippets vscode-snippets vuejs-snippets

vue-vscode-snippets's Introduction

Vue VSCode Snippets

vue-snippet-hero

Description

These snippets were built to supercharge a workflow in the most seamless manner possible.

This 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

Snippet Purpose
vbase Single file component base with SCSS
vbase-3 Single File component Composition API with SCSS
vbase-3-setup Single File component setup Composition API with SCSS
vbase-3-reactive Single File component Composition API with Reactive and SCSS
vbase-css Single file component base with CSS
vbase-pcss Single file component base with PostCSS
vbase-styl Single file component base with Stylus
vbase-ts Single file component base with Typescript
vbase-ts-class Single file component base with Typescript Class Format
vbase-3-ts Single File component Composition API with Typescript
vbase-3-ts-setup Single File component setup Composition API with Typescript
vbase-ns Single file component with no styles
vbase-sass Single file component base with SASS
vbase-less Single file component base with LESS

Template

Snippet Purpose
vfor v-for directive
vmodel Semantic v-model directive
vmodel-num Semantic v-model number directive
von v-on click handler with arguments
vslot-named Named slot
vel-props Component element with props
vsrc Image src binding
vstyle Inline style binding
vstyle-obj Inline style binding with objects
vclass Class binding
vclass-obj Class binding with objects
vclass-obj-mult Multiple conditional class bindings
vanim Transition component with JS hooks
vnuxtl Nuxt Routing Link
vroutename router-link Named Routing
vroutenameparam router-link Named with Parameters
vroutepath router-link Path Routing Link
vemit-child Emit event from child component
vemit-parent Emit event to parent component

Script

Snippet Purpose
vdata Component data as a function
vmethod Vue method
vcomputed Vue computed property
vwatcher Vue watcher with new and old value args
vbeforecreate beforeCreate lifecycle method
vcreated created lifecycle method
vbeforemount beforeMount lifecycle method
vmounted vmounted lifecycle method
vbeforeupdate beforeUpdate lifecycle method
vupdated updated lifecycle method
vbeforedestroy beforeDestroy lifecycle method
vdestroyed destroyed lifecycle method
vprops Props with type and default
vimport Import one component into another
vimport-dynamic Import one component that should be lazy loaded by webpack
vcomponents Import one component into another within the export statement
vimport-export Import one component into another and use it within the export statement
vmapstate import mapState from Vuex into vue component component
vmapgetters import mapGetters from Vuex into vue component component
vmapmutations import mapMutations from Vuex into vue component component
vmapactions import mapActions from Vuex into vue component component
vfilter Vue filter
vmixin Create a Vue Mixin
vmixin-use Bring a mixin into a component to use
vc-direct Vue create a custom directive
vimport-lib Import a library
vimport-gsap Import GreenSock
vanimhook-js Using the Transition component JS hooks in methods
vcommit Commit to Vuex store in methods for mutation
vdispatch Dispatch to Vuex store in methods for action
vtest A simple unit testing component

Vue Composition API

Snippet Purpose
v3reactive Vue Composition API - reactive
v3reactive-setup Vue Composition API - reactive with setup boilerplate
v3computed Vue Composition API - computed
v3watch Vue Composition API - watcher single source
v3watch-array Vue Composition API - watch as array
v3watcheffect Vue Composition API - watchEffect
v3ref Vue Ref
v3onmounted Lifecycle hook - onMounted
v3onbeforemount Lifecycle hook - onBeforeMount
v3onbeforeupdate Lifecycle hook - onBeforeUpdate
v3onupdated Lifecycle hook - onUpdated
v3onerrorcaptured Lifecycle hook - onErrorCaptured
v3onunmounted Lifecycle hook - (destroyed) onUnmounted
v3onbeforeunmount Lifecycle hook - (beforeDestroy) onBeforeUnmount
v3useinoptions Use Composition API in Options API

Vuex

Snippet Purpose
vstore Base for Vuex store.js
vgetter Vuex Getter
vmutation Vuex Mutation
vaction Vuex Action
vmodule Vuex Module
vstore-import Import vuex store into main.js
vstore2 Updated Base for Vuex store

Vue Router

Snippet Purpose
vrouter Vue Router base
vscrollbehavior Vue Router scrollBehavior
vbeforeeach Vue Router global guards beforeEach
vbeforeresolve Vue Router global guards beforeResolve
vaftereach Vue Router global guards afterEach
vbeforeenter Vue Router per-route guard beforeEnter
vbeforerouteenter Vue Router component guards beforeRouteEnter
vbeforerouteupdate Vue Router component guards beforeRouteUpdate
vbeforerouteleave Vue Router component guards beforeRouteLeave

Vue Config

Snippet Purpose
vplugin Import a plugin to main.js or plugins file
vconfig vue.config.js file, example imports a sass file into every component

Nuxt Config

Snippet Purpose
nfont link to include fonts in a nuxt project, in nuxt-config
ncss link to css assets such as normalize

Nuxt Page

Snippet Purpose
nasyncdata Nuxt asyncData
nasyncdataaxios Nuxt asyncData with Axios module
nfetch Nuxt Fetch
nfetchaxios Nuxt Fetch with Axios module
nhead Nuxt Head
nparam Nuxt Route Params

Extra (plaintext)

Snippet Purpose
gitignore .gitignore file presets

Contributing

This is an open source project open to anyone. Contributions are welcome github

If you are contributing a snippet, please be sure to add the documentation for it in the tables in the README, the pull request cannot be accepted without this addition. Thanks!

vue-vscode-snippets's People

Contributors

afflexux avatar christhofer avatar cromodder avatar darrenjennings avatar dasdaniel avatar debs-obrien avatar dolbex avatar dominuskelvin avatar elsaooo avatar jeroendewilde avatar johnpyp avatar joshukraine avatar joy-yu avatar lissetteibnz avatar loilo avatar luke-wilson avatar maatthc avatar mattmcmurray avatar n9ti avatar octref avatar pawelmadeja avatar roninii avatar sdras avatar shika358 avatar sidharthv96 avatar simonhermann avatar swvv avatar tahul avatar wanxe avatar zwik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-vscode-snippets's Issues

[Request] Publish extension on open-vsx.org

Hi there!

I'm reaching out to you because we currently have your extension manually added to our extension gallery at Coder for code-server, and we're currently working on a migration to open-vsx, which is also used by other community VSCode forks (including, but not limited to Arch Linux's Code-OSS builds and VSCodium).

We (and other open source VSCode forks) cannot use Microsoft's extension gallery, as MS' terms of service allows only the proprietary MS products to interact with the official gallery.

We'd really appreciate it if you can add your extension to open-vsx! A simple guide on publishing extensions to Open-VSX is available here.

Incompatible with older version of code (<1.15)

Trying to install extension on older version(I run 1.14.2) of code trows an error:

Couldn't find a compatible version of Vue VSCode Snippets with this version of Code.

Downgrading vscode verision of engines in package would solve the problem.
It would be nice to support >=1.14, but feel free to close this issue if you don't see benefit of downgrading.

Typescript Support

It would be nice if these were available to typescript code as well.

With vetur, typescript snippets will work in a <script lang="ts"> section. Think the snippets just need to be registered as "typescript", as well as javascript.

Snippets overview recommendation

Hi Sarah,

I'm a happy user of this extension. Thank you! 🙂

I would like to recommend an easy way to get an overview of the snippets. Maybe I can add this as recommendation to the README?

I switch between technologies regularly, which makes me prone to forget prefixes. To compensate for this, I wrote an extension that gives a nice UI for all available snippets. It is called Snippets Ranger, you can see a screenshot below. It's on the right.

vue-snippets

While your README is ship-shape, others are not so conscientiousness! In any case, I find it great to have them all at my fingertips, with a few keystrokes, just like a snippet! It's a nice little win!

If you don't think it's appropriate, no problemo! 🙂

Best wishes

Rob

Improvement on snippets

Hey Sarah. Thanks for sharing your snippets by making it an extension and marking Vetur as a dependency.

In the demo, some stuff were not working correctly, so I'm here to ask for your setup and make the right PR to improve the snippets.

  1. Vetur offers some scaffold snippets, so vbase might be unnecessary

1

  1. I didn't see the snippets showing up in your gif (they should show up like IntelliSense items). For example, how did you get vanim to expand in the <template> in your gif?

Here is how it should be:

2

  1. Vetur divides vue files into "regions" with specific languages, and snippets should be declared according to the regions that they belong to. For example,
<template>
<!-- vue-html region -->
</template>
<!-- vue region -->
<style lang="scss">
.hi { // scss region
  color: red;  // scss region
}  // scss region
</style>
<!-- vue region -->

The idea is, each "region" has a language defined by lang value, with the exception of <template>, which has language vue-html.

Now you are marking everything as js snippets, so they would be available only in <script>, which is wrong for vanim etc:

3

The correct way is to divide template / js snippets into two files, and change the language associations (template to vue-html, js to javascript) in your contributes.snippets in package.json. Top level snippets, such as vbase should be associated for language vue.

Let me know how you want to proceed. I can soon send a PR that

  • removes vbase as it's covered by scaffold snippets
  • puts snippets into different files and associates them with correct languages

Add unit test snippet

Test every component looks have a lot in common, can we make this a snippet ?

import Vue from 'vue'
import HelloWorld from '@/components/HelloWorld'

describe('HelloWorld.vue', () => {
  it('should render correct contents', () => {
    const Constructor = Vue.extend(HelloWorld)
    const vm = new Constructor().$mount()
    expect(vm.$el.querySelector('.hello h1').textContent)
      .to.equal('Welcome to Your Vue.js App')
  })
})

Add in Docker Snippet

I have one that's already kind of there, need to organize it a bit and put it in here.

how about webstrom?

感觉挺好用的,极大简化开发工作。但是,how about webstrom? 支持webstrom么?

Add in vuex modules snippet

Please add in store modules scaffolding "vstore-module".

const state = () => ({
data: ''
});

const getters = {
};

const actions = {
};

const mutations = {
};

export default {
namespaced: true,
state,
getters,
actions,
mutations
};

Less

I could not find an option to choose less as the preferred language for the template.

Nice extension, thx

don't work

I installed vue snippets, but its not work. Vetur is installed too

bug in beforeEach and afterEach?

First off, excellent set of snippets, thank you.

I'm walking through them all, and think I may have found bugs in beforeEach and afterEach for the Vue Router set.

I believe each should have a closing paren to match the opening. That is, for beforeEach:

"Vue Router beforeEach": { "prefix": "vbeforeeach", "body": [ "router.beforeEach((to, from, next) => {", "\t${1:next();}", "};" ], "description": "Vue Router global guards beforeEach" },

should be:

"Vue Router beforeEach": { "prefix": "vbeforeeach", "body": [ "router.beforeEach((to, from, next) => {", "\t${1:next();}", "});" ], "description": "Vue Router global guards beforeEach" },

vbase dont work on win10

image

The first time I typed this command after install this snippet works well, but it only works well once.

Test snippets

I'm just curious if you feel as though snippets directed at test files are out of the scope of this extension? I thought about making a separate extension, but I figured we could just add on to this one if you feel it's within the same scope?

i.e. using @testing-library/vue:

import { render } from '@testing-library/vue'
import MyComponent from '@/components/MyComponent.vue'

descibe('', () => {
    it('', () => {
        //... test...
    })
})

Why:

  • User generated snippets can't be scoped by file extensions like *.spec.js.
  • We should all probably write more tests, and testing boiler plate is obnoxious.

Edit: I should note that I bring this up because I'm willing to create some snippets. Just wondered if the interest was there :D

theme?

The theme is so soft, could you tell me about this ?   😂

vmutation

In Vuex mutation snippet there is a colon added after the mutation name.

gitignore snippet does not work

The gitignore snippet does not trigger in a .gitignore file, since VSCode autodetects these files as "Ignore"-filetype instead of "Plain Text".

Missing Router Methods

I think it will be more feature-packed if we can include a router method like push, replace, etc.

Hope to optimize the support of the composition api, which can return at the same time when I define the variables or functions.

Hi, sdras!

At last month, Vue 3.0 was released, I using Vue 3.0 with the Composition Api and TypeScript now.

This vscode plugin is very good! But I encountered a little problem in the process of using.

example:

I can use this command ts to quickly create a Vue component.It's very convenient!

<template>
  <div>

  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue'

export default defineComponent({
  setup () {
    

    return {}
  }
})
</script>

<style scoped>

</style>

Then, if I want to start using the composition api to create some data or functions, follow the official specification, I must first define the variable and then return it to use.

The current problem is that through some shortcut commands, such as v3reactive, I can quickly create a variable, but cannot return it synchronously.

example:

import { defineComponent } from 'vue'

export default defineComponent({
  setup () {
    const name = reactive({
      count: 0
    })

    return {}
  }
})

I hope to help developers return these data synchronously when defining variables or functions.

Thank you very much!

Configure custom snippet for vue-script

Hello,

I know it might not be the best place to ask, but how to add a custom snippet that works only in vue-script?

I've tried to add a new file vue-script.json like your snippets, but VSCode didn't recognize it

vrouter snippet bug

vrouter snippet has a curly brace where it should be a bracket.

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

Vue.use(VueRouter);

export const router = new VueRouter({
base: '/',
mode: 'history',
routes: [
{ path: '/path', component: component }
}
});`

Volar suddenly being forced?

I just logged on to start working - and now every single vue file in my project is getting marked with an error message from Volar on every single line, even though I've been using Vetur for my project. This extension was being marked as the culprit. Can you please revert whatever changes you made?

Snippets for WebStorm

Hi!
My name is Ekaterina and I'm from the WebStorm team.
Thank you for building this collection of code snippets! We really like it!
We want to ask you permission to adapt them for WebStorm (and all other JetBrains IDEs) and make available as part of the Vue.js plugin we have. The plugin is open source, however, it only works with the paid IDE we have.
Thanks!

What about Volar?

Why this snippets are based on Vetur? I like to use it with Volar. Is it possible?

vprops modification suggestion

This may be personal preference, however when using vprops I typically am looking to create a prop that takes a String and that prop name is usually title.

Perhaps we could streamline things a bit more by changing the default vprops to these.

This isn't exactly generic but will do what snippets are supposed to do, which is help you work faster.

For now, I've just modified this in the snippets folder to cover this need for myself, but this will of course disappear whenever the extension is updated.

Remove scss as default style lang attribute in vbase

Hey,

Thanks for the awesome snippets! I'm not sure when this changed, fairly recently, but the style's lang attribute in vbase now defaults to scss. I have to delete it every time I use vbase which is pretty often. Can we revert it back to what it was if possible?

Thanks

<style lang="scss" scoped>

</style>

Vue Router Snippets

Please add snippets for vue-router

vroutename
<router-link :to="{name: 'foo'}">link to foo</router-link>

vroutepath
<router-link to="/foo">link to foo</router-link>

And if possible, also include params/query
<router-link :to="{name: 'foo', params:{id: 2}}">link to foo</router-link>

Typing this is very tedious, and idk why, my vue custom snippets not working.

pug snippets do not work

I've not been able to use any of the pug snippets. I guess, it could be related to the snippet configuration. Can you check it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.