component组件
Vue.component("名字",{template:“鱼塘”})
js定义用驼峰 html中用-
全局组件注册:
Vue.extend({})
注册Vue.component("abc",构造器)
注册使用 abc
Vue.extend({
template:"",
data:function(){
return {键名:键值}
简写 data(){
}
方法2:
let 对象={
template:“”
data(){}
}
Vue.component();
}
})
方法三
定义一个有id的script标签 type=“text/html”
let obj={
template:"#id"
}
Vue.component(“标签名”,定义的组件)
最终
html里面写<template id="></template>
script里面
let 组件名 ={
template:“#id”
}
Vue.component("标签名",组件);
局部组件
template标签
new Vue({
el:“#盒子id”,
components:{
组件名:{
template:“templateid”,
data(){
return {}
}
}
}
});
动态组件:
<component is="">
相当于if 会销毁重建
<keep-alive> 会缓存切换组件
父子组件
在其他组件里面定义别的组件
子组件里面加自定义属性:属性名=“父组件数据的键名”
子组件里面的props:[数组] |
|