vue常用实例属性

1、vm.$el:类型(HTMLElement)挂载元素,Vue实例的DOM根元素;

2、vm.$data:类型(Object),Vue实例观察的数据对象

3、vm.$options:类型(Object),用于当前Vue实例的初始化选项,在选项中需要包含自定义属性的时候很有用。

console.log(vm.$options); // Object {components: Object, directives: Object, filters: Object, el: "#app", customOption: "foo"…}
console.log(vm.$options.customOption); // 'foo'
console.log(vm.$options.el);  // '#app'

4、vm.$refs:类型(Object),一个对象,其中包含了所有拥有 ref 注册的子组件;

<input type="text" ref="name" value="this is text"/>
<p ref="hello">HelloWorld</p>

console.log(vm.$refs.hello);

5、vm.$root:类型(Vue实例),当前组件树的根Vue实例,如果没有父实例,就是实例本身。

猜你喜欢

转载自blog.csdn.net/qq_37530404/article/details/86503516