Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bind Vue on body or others element

Tags:

vue.js

I've seen many times Vue instance is bind on body tag. Other times this is bind on a div id

I'm asking when i should use body tag or an id tag (that limit the scope of the Vue instance).

Two examples:

new Vue({
  el: 'body'
});

OR

new Vue({
  el: '#a-div'
});
like image 438
Mistre83 Avatar asked Aug 26 '16 11:08

Mistre83


People also ask

What is the difference of using V-if V else if V else or V-show only?

The key difference is that v-if conditionally renders elements and v-show conditionally displayselements. This means that v-if will actually destroy and recreate elements when the conditional is toggled. Meanwhile, v-show will always keep the element in the DOM and will only toggle its display by changing its CSS.

What does V-bind do in Vue?

The v-bind directive is a Vuejs directive used to bind one or more attributes, or a component prop to an element. If that attribute is binded to our data defined in Vuejs instance then dynamically changes can be observed as data changes.

What is the difference between v-model and V-bind?

v-model is for two way bindings means: if you change input value, the bound data will be changed and vice versa. But v-bind:value is called one way binding that means: you can change input value by changing bound data but you can't change bound data by changing input value through the element.

What is $t in Vuejs?

Vuex is a state management pattern for vue. js. $t is the injected method from vue. js or Vue.


1 Answers

You should never use the body tag. In fact, it raises a warning to use the body tag.

Added a warning when mounting the root instance to body or html. This is no longer recommended in 2.0.

This is from the release notes, anyways it's incorrect, it raises an error.

like image 175
gurghet Avatar answered Oct 13 '22 05:10

gurghet