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
16
votes
3 answers

Vue-i18n - Cannot read property 'config' of undefined

First of all I show you what works (in App.js) import router from './routes.js'; import VueI18n from 'vue-i18n'; const messages = { en: { message: { hello: 'hello world' } } } // Create VueI18n instance with options const i18n =…
Philipp Mochine
  • 4,351
  • 10
  • 36
  • 68
16
votes
2 answers

How to use mapGetters with modules and root's getters at the same time?

I know how to use mapGetters in a single situation, but not both. Example, I have firstRootGetter inside store/index.js, so I will call ...mapGetters(['firstRootGetter']) in vue component. If I have firstModuleGetter and secondModuleGetterinside…
Sang Dang
  • 501
  • 1
  • 11
  • 26
16
votes
5 answers

Way to make inheritance in Vuex modules

Im building my app with VueJS and Vuex and I'm facing the issue when I have Multiple modules using the same data fields. Its about API configuration like dat. getUsers ({ state, commit }) { axios.get(urls.API_USER_URL).then( response => { …
Canor
  • 909
  • 1
  • 8
  • 25
16
votes
1 answer

Bulma - why all columns are on one line?

I use Bulma with VueJS when I use v-for, all columns are on one line, I tried to addis-4, then the column width changes but they are still on one line
Mateusz Kawka
  • 422
  • 1
  • 4
  • 16
16
votes
2 answers

Vuejs . What do $v And $event denotes in Vuejs?

What do $v and $event denote in Vue.Js? What and in which situations do we use these. Please elaborate in detail with examples too.
Sandeep Ghimire
  • 169
  • 1
  • 1
  • 3
16
votes
2 answers

Setting id tag dynamically using vuejs

I have a vue.js template that has a todo prop. I want to dynamically set the id value of each element. This what I have tried so far, is something like this possible and if not what are some other options?
Taylor
  • 1,223
  • 1
  • 15
  • 30
16
votes
8 answers

vuejs history mode with github/gitlab pages

Has anyone managed to figure out how to make Vue.js work with history mode with GitHub or GitLab Pages? It works with hash mode, but I don't want to use hash mode for SEO related reasons. Reference for router modes:…
fisker
  • 979
  • 4
  • 18
  • 28
16
votes
3 answers

Determining if slot content is null or empty

I have a little Loading component, whose default text I want to be 'Loading...'. Good candidate for slots, so I have something like this as my template:

Loading...

That allows…
John Moore
  • 6,739
  • 14
  • 51
  • 67
16
votes
5 answers

Vuetify Form Validation - defining ES6 rules for matching inputs

I have a (Vuetify) form with an email input that uses ES6 & regex to check if it's a valid email. How would I set up another emailConfirmationRules ruleset to check if the emailConfirmation input matches the email input?