Questions tagged [vue.js]

Vue.js is an open-source, progressive JavaScript framework for building user interfaces that aims to be incrementally adoptable. Vue.js is mainly used for front-end development and requires an intermediate level of HTML and CSS. Vue.js questions are highly version specific and should always be tagged with [vuejs2] or [vuejs3] in addition to this tag.

What is Vue.js?

Vue.js is an open-source, progressive JavaScript framework for building user interfaces that aims to be incrementally adoptable.

Instead of performing manual updates to the DOM, which can be repetitive and error prone (think jQuery), Vue embraces the idea of "data-driven views," where changes in data drive changes in the DOM.

This idea forms the core of Vue.js: a reactive data-binding system that is designed to make it extremely simple to keep your data and the DOM in sync.

Vue data-binding diagram

What makes Vue particularly powerful, however, is that it can be built upon, increasing its functionality from a simple view-model library to that of a fully fledged JavaScript framework capable of powering entire SPA's via supporting plugins and libraries such as Vue Router, Vue Resource, and Vuex.


Features

Vue.js includes:

2.0 also includes:

Vue 3.0 is currently in development, and includes some notable changes and improvements detailed here on VueJS.org.

Questions that are version specific should be tagged with or respectively.

Vue is compatible with all ES5-compliant browsers. As such, IE8 and below are unsupported.

To check out an in-depth guide with live examples or the official docs, visit vuejs.org.


Code Example

All that is required to use Vue in a project is to create a Vue instance, and tell it where to render in the DOM. Vue handles the rest!

The code below forms a simple, fully functioning Vue app:

<html>
<div id="demo">
  <p>{{ message }}</p>
  <input v-model="message">
</div>

<script src="https://unpkg.com/vue@2"></script>
<script>
  new Vue({
    el: '#demo', //Tells Vue to render in HTML element with id "demo"
    data() {
      return {
        message: 'Hello Vue.js!'
      }
    }
  });
</script>
</html>

See a live and editable version here.


Related Tags

UI Frameworks built with Vue.js

Tooling

Resources


Official Logo:


Using Vue in Stack Snippets

It is often useful to share runnable snippets of code in questions regarding Vue components. Since Stack Snippets can't natively run Vue single file components (.vue files), it's necessary to do a little conversion work.

To create a Stack Snippet containing Vue in a Stack Overflow post, make sure you:

  1. Import Vue into the HTML section of the snippet
    • You can do this through the sidebar of the snippet editor itself:
      Vue version select in snippet editor sidebar
    • Or by manually adding a <script> tag
      (eg. <script src="https://unpkg.com/vue@2"></script>)
    • NOTE: It's important that the Vue import is before other imports of libraries that depend on Vue (eg. Vue Router)
  2. Wrap component JavaScript with new Vue({...})
    • Replace default export with new Vue, and don't forget the parenthesis () around your brackets {}
    • Note that you won't be able to use import statements, so you should trim everything out of the snippet that's not strictly necessary to understand your question and the problem at hand
    • You may also need to add example data if your component relied on props or APIs
  3. Tell the new Vue instance where to render in your HTML
    • Use the el property of the new Vue instance to indicate what HTML container Vue should render in (see example below)

You may also want to replace your <template> HTML elements with some alternative (ie. <div>) if it causes issues.

Starting with something like this:

HelloWorld.vue

<template>
  <div>
    <p>{{ message }}</p>
    <input v-model="message">
  </div>
</template>

<script>
  export default {
    data() {
      return {
        message: 'Hello World!'
      }
    }
  }
</script>

Will end up with something like this:

HelloWorld.html

<html>
<div id="app">
  <p>{{ message }}</p>
  <input v-model="message">
</div>

<!-- Don't forget to include Vue from CDN! -->
<script src="https://unpkg.com/vue@2"></script>
<script>
  new Vue({
    el: '#app', //Tells Vue to render in HTML element with id "app"
    data() {
      return {
        message: 'Hello World!'
      }
    }
  });
</script>
</html>

You can drop this straight into the HTML section of a snippet, or split it into the HTML and JavaScript sections accordingly. Bear in mind that splitting it may make the code clearer to readers!

105350 questions
200
votes
3 answers

Optional param in vuejs router

I need to route to a certain component in two ways - one with a param, one without. I have searched for optional params and somehow can't find much info. So my route: { path: '/offers/:member', component: Offers, name: 'offers', …
yoyoma
  • 3,336
  • 6
  • 27
  • 42
196
votes
18 answers

Do we have router.reload in vue-router?

I see in this pull request: Add a router.reload() Reload with current path and call data hook again But when I try issuing the following command from a Vue component: this.$router.reload() I get this error: Uncaught TypeError:…
Saurabh
  • 71,488
  • 40
  • 181
  • 244
194
votes
12 answers

How do I hide the VueJS syntax while the page is loading?

maybe this is a trivial question. so, when I run my vuejs application on browser with enables throttling download speed (sets to low connection). I got unfinished vue syntax output in browser. I know we can trick this out with showing loading image…
antoniputra
  • 4,251
  • 6
  • 26
  • 31
191
votes
20 answers

Vue: How do I call multiple functions with @click?

How can I call multiple functions in a single @click? (aka v-on:click)? So far I tried Splitting the functions with a semicolon:
; Using several @click:
S Panfilov
  • 16,641
  • 17
  • 74
  • 96
190
votes
4 answers

Default values for Vue component props & how to check if a user did not set the prop?

1. How can I set the default value for a component prop in Vue 2? For example, there is a simple movies component that can be used in this way: Vue.component('movies', { props: ['year'], template:…
PeraMika
  • 3,539
  • 9
  • 38
  • 63
189
votes
5 answers

What is nextTick and what does it do in Vue.js?

I read the docs, but I still can't understand it. I know what data, computed, watch, methods do, but what is nextTick() used for in Vue.js?
hidar
  • 5,449
  • 15
  • 46
  • 70
185
votes
14 answers

Moment.js with Vuejs

I try to print out date time using like the following in vue-for {{ moment().format('MMMM Do YYYY, h:mm:ss a') }} but, it does not appear. It's just a blank. How I can try to use moment in vue?
Set Kyar Wa Lar
  • 4,488
  • 4
  • 30
  • 57
183
votes
3 answers

Vue CLI CSS pre-processor option: dart-sass VS node-sass?

When creating a new project with CLI (v3.7.0), there is an option to choose between dart-sass or node-sass compiler. How do these compare to each other, to be more specific than declared in Vue docs? A Tip on Sass Performance Note that when using…
ux.engineer
  • 10,082
  • 13
  • 67
  • 112
183
votes
28 answers

[Vue warn]: Property or method is not defined on the instance but referenced during render

The following code has been written to handle an event after a button click var MainTable = Vue.extend({ template: "
182
votes
13 answers

Can vue-router open a link in a new tab?

I have a summary page and a detail subpage. All of the routes are implemented with vue-router (v 0.7.x) using programmatic navigation like this: this.$router.go({ path: "/link/to/page" }) However, when I route from the summary page to the subpage,…
Tang Jiong
  • 1,893
  • 2
  • 11
  • 9
182
votes
16 answers

Vue.js: How to set a unique ID for each component instance?

I want to create a component with Vue.js containing a label and an input. For example : How can I set a unique ID for each component instance?
PierreB
  • 1,947
  • 3
  • 16
  • 16
181
votes
5 answers

Vuex - Computed property "name" was assigned to but it has no setter

I have a component with some form validation. It is a multi step checkout form. The code below is for the first step. I'd like to validate that the user entered some text, store their name in the global state and then send then to the next step. I…
Connor Leech
  • 18,052
  • 30
  • 105
  • 150
180
votes
9 answers

Handling Enter Key in Vue.js

I have a text field and a button. By default, this button submits a form when someone presses the Enter key on their keyboard. When someone is typing in the text field, I want to capture each key pressed. If the key is an @ symbol, I want to do…
user687554
  • 10,663
  • 25
  • 77
  • 138
179
votes
6 answers

Vue.js get selected option on @change

I have a combobox and want to do something different based on the selected combobox. I use a separate vue.html and TypeScript file. Here's my code: