What the Vue JS Formatter does
The Vue JS Formatter formats Vue single-file components with Prettier 3.3.3, an open-source code formatter, running in your browser. It supports Vue single-file components: template, script and style blocks.
Vue JS Formatter examples
The built-in sample
Input
<template><ul><li v-for="i in items" :key="i.id" @click="pick(i)">{{i.name}}</li></ul></template>
<script>
export default {data(){return {items:[]}}}
</script>
<style scoped>
li{color:red}
</style>Output
<template>
<ul>
<li v-for="i in items" :key="i.id" @click="pick(i)">{{ i.name }}</li>
</ul>
</template>
<script>
export default {
data() {
return { items: [] };
},
};
</script>
<style scoped>
li {
color: red;
}
</style>
This is the input that the Load sample button fills in.
TypeScript script block and SCSS styles
Input
<script setup lang="ts">
const props=defineProps<{msg:string}>()
</script>
<template><p :class="{on:active}">{{msg}}</p></template>
<style lang="scss">
.a{.b{color:red}}
</style>Output
<script setup lang="ts">
const props = defineProps<{ msg: string }>();
</script>
<template>
<p :class="{ on: active }">{{ msg }}</p>
</template>
<style lang="scss">
.a {
.b {
color: red;
}
}
</style>
Each block is formatted with the rules of its own language: TypeScript in the script, the binding expression and the interpolation in the template, and nested SCSS in the style block.
Each output was produced by running this tool on the input above it.
How it works
The code is parsed with Prettier's vue parser and printed again from its syntax tree, using Prettier's default options: lines up to 80 characters and two-space indentation. The result therefore does not depend on how the input was laid out. If the code cannot be parsed, the parser's message with its line and column is shown instead of output.
Details and limits
- A single-file component is expected:
template,scriptandstyleblocks at the top level. - A template written in Pug (
lang="pug") is left exactly as it is. - By Prettier's default, the code inside
scriptandstyleis not indented one extra level relative to its tag. - Directive expressions such as
v-for,v-if,:propand@eventare formatted as JavaScript.
Questions
Is my data uploaded when I use Vue JS Formatter?
No. The tool runs in your browser, so what you paste or open is processed on your own device and is not sent to a server.
What does Vue JS Formatter do?
The Vue JS Formatter formats Vue single-file components with Prettier 3.3.3, an open-source code formatter, running in your browser. It supports Vue single-file components: template, script and style blocks.
How does Vue JS Formatter work?
The code is parsed with Prettier's vue parser and printed again from its syntax tree, using Prettier's default options: lines up to 80 characters and two-space indentation. The result therefore does not depend on how the input was laid out.
Are there any limits I should know about?
A single-file component is expected: template, script and style blocks at the top level. A template written in Pug (lang="pug") is left exactly as it is.
Is there a size limit?
There is no fixed size limit. Everything happens on your device, so very large inputs depend on its memory and can take longer on a phone than on a computer.
Does it work on phones, and is it free?
Yes. It works in any current browser on Android phones, iPhones, tablets and computers. It is free and needs no account or sign-up.