在 body 或其他元素上绑定 Vue [英] Bind Vue on body or others element

查看:91
本文介绍了在 body 或其他元素上绑定 Vue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经多次看到 Vue 实例绑定在 body 标签上.其他时候这是绑定在 div id

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

我在问什么时候应该使用 body 标签或 id 标签(限制 Vue 实例的范围).

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

两个例子:

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

new Vue({
  el: '#a-div'
});

推荐答案

你永远不应该使用 body 标签.事实上,使用 body 标签会引发警告.

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

在将根实例安装到 body 或 html 时添加了警告.这在 2.0 中不再推荐.

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.

这篇关于在 body 或其他元素上绑定 Vue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆