Skip to main content

Vue.js Syntax Guide


ConceptSyntax
Component<template>, <script setup>, <style>
import Component from "./components/Component.vue"
Propsconst props = defineProps({ propName: { type: String } })
props.propName
Reactive Variableimport { ref } from 'vue'
const variableName = ref(initialValue)
Interpolation{{ variableName }}
Bindingv-bind:attribute="variableName", :attribute="variableName"
Class Binding:class="{ 'class-name': condition }"
Bi-directional Bindingv-model="variableName"
Event Handlingv-on:event="methodName", @event="methodName"
Emitsconst emit = defineEmits(['event-name'])
emit('event-name', payload)
Conditional Renderingv-if="condition", v-else-if="condition", v-else
Render Listv-for="item in items", :key="item.id"
Watchimport { watch } from 'vue'
watch(variableName, (newValue, oldValue) => { /* ... */ })

Additional Resources​

You may also access and use the following resources during the exam without penalty: