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
776
votes
20 answers

What is "not assignable to parameter of type never" error in TypeScript?

Code is: const foo = (foo: string) => { const result = [] result.push(foo) } I get the following TS error: [ts] Argument of type 'string' is not assignable to parameter of type 'never'. What am I doing wrong? Is this a bug?
Lev
  • 13,856
  • 14
  • 52
  • 84
697
votes
16 answers

Vue.js - How to properly watch for nested data

I'm trying to understand how to properly watch for some prop variation. I have a parent component (.vue files) that receive data from an ajax call, put the data inside an object and use it to render some child component through a v-for directive,…
Plastic
  • 9,874
  • 6
  • 32
  • 53
559
votes
47 answers

Why does Prettier not format code in VS Code?

In my Nuxt application where ESlint and Prettier are installed and enabled, I switched to Visual Studio Code. When I open a .vue file and press CMD+ Shift + P and choose Format Document, my file does not get formatted at all. My .prettierrc…
Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
535
votes
13 answers

How can I get query parameters from a URL in Vue.js?

How can I fetch query parameters in Vue.js? E.g. http://somesite.com?test=yay Can’t find a way to fetch or do I need to use pure JS or some library for this?
Rob
  • 10,851
  • 21
  • 69
  • 109
491
votes
21 answers

How to listen for 'props' changes

In the VueJs 2.0 docs I can't find any hooks that would listen on props changes. Does VueJs have such hooks like onPropsUpdated() or similar? Update As @wostex suggested, I tried to watch my property but nothing changed. Then I realized that I've…
Amio.io
  • 20,677
  • 15
  • 82
  • 117
470
votes
18 answers

How to fix 'Unchecked runtime.lastError: The message port closed before a response was received' chrome issue?

I'm using VueJS and Laravel for my project. This issue started to show lately and it shows even in the old git branches. This error only shows in the Chrome browser.
3UMF
  • 5,162
  • 2
  • 15
  • 26
434
votes
16 answers

Disable input conditionally (Vue.js)

I have an input: and in my Vue.js component, I have: .. .. ready() { this.form.name = this.store.name; …
Zaffar Saffee
  • 6,167
  • 5
  • 39
  • 77
427
votes
13 answers

What does the @ mean inside an import path?

I'm starting out a new vue.js project so I used the vue-cli tool to scaffold out a new webpack project (i.e. vue init webpack). As I was walking through the generated files I noticed the following imports in the src/router/index.js file: import Vue…
Chris Schmitz
  • 20,160
  • 30
  • 81
  • 137
396
votes
22 answers

Can you force Vue.js to reload/re-render?

Just a quick question. Can you force Vue.js to reload/recalculate everything? If so, how?
Dave
  • 12,117
  • 10
  • 46
  • 52
368
votes
5 answers

Difference between v-model and v-bind on Vue.js?

I'm learning Vue with an online course and the instructor gave me an exercise to make an input text with a default value. I completed it using v-model but, the instructor chose v-bind:value, and I don't understand why. Can someone give me a simple…
Gustavo Dias
  • 3,811
  • 3
  • 11
  • 6
362
votes
16 answers

Vue.js - How to remove hashbang #! from url?

How to remove hashbang #! from url? I found option to disable hashbang in vue router documentation ( http://vuejs.github.io/vue-router/en/options.html ) but this option removes #! and just put # Is there any way to have clean url? Example: NOT:…
DokiCRO
  • 4,565
  • 3
  • 20
  • 22
349
votes
17 answers

TypeError: this.getOptions is not a function

I am facing a weird error when I installed Bootstrap. The error is below. I tried uninstalling less-loader and installing less-loader@5.0.0, because I saw it online, but it did nothing. I am unsure what to do at this step. Syntax Error: TypeError:…
Juliette
  • 4,309
  • 2
  • 14
  • 31
340
votes
13 answers

Can I pass parameters in computed properties in Vue.Js

is this possible to pass parameter in computed properties in Vue.Js. I can see when having getters/setter using computed, they can take a parameter and assign it to a variable. like here from documentation: computed: { fullName: { // getter …
Saurabh
  • 71,488
  • 40
  • 181
  • 244
336
votes
15 answers

Call a Vue.js component method from outside the component

Let's say I have a main Vue instance that has child components. Is there a way of calling a method belonging to one of these components from outside the Vue instance entirely? Here is an example: var vm = new Vue({ el: '#app', components:…
harryg
  • 23,311
  • 45
  • 125
  • 198
309
votes
22 answers

How to watch store values from vuex?

I am using vuex and vuejs 2 together. I am new to vuex, I want to watch a store variable change. I want to add the watch function in my vue component This is what I have so far: import Vue from 'vue'; import { MY_STATE, } from…
raffffffff
  • 3,447
  • 4
  • 16
  • 15
1
2 3
99 100