vue.js基础学习(2)

vm=new vue({

date:{name:"aa",

user:{“name”:"lsm"}});

获取属性值

1:vm.name

2:vm.$data.name

3:获取vue关联的实例  vm.$el

vm.$el.style.color="red"

4:获取自定义属性

vm.$options.name

5:获取所有添加了ref属性的元素

vm.$refs         <h2 ref="hello"></h2>    vm.$el.hello.style.color="red"

6:$set  $delete  对象属性的添加和删除

method:{

add(){

this.$set(this.user,"age",22)

}

del(){

this.$delete(this.user,"age")

}

}

7:全局组件

创建方法1:var Component =vue.extend({

template:'<h1>hello</h1>'

})

vue.component(“hello”,Component)

 创建方法2: vue.component(“wrold”{

template:'<h1>wrold</h1>'

})

引用:<hello></hello>

8:局部组件

components:{

"my-adress":{

template:'<h1>wrold</h1>'},

"my-name":{

template:'<h1>{{name}}</h1>',

data(){

return {"name":"lsm"}}}

}

猜你喜欢

转载自www.cnblogs.com/min-min-min/p/10043405.html