vue.js基础__component 继承
component 继承就是父子组件的关系,在构造器外部写局部注册组件;
如果把局部组件的编写放到构造器内部,若组件代码量很大,会影响构造器的可读性,造成拖拉和错误;
所以要把组件填写的代码放到构造器外部或者说成单独组件;
应先声明一个对象,对象里就是组件的内容,代码示例如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>componen-3 继承</title>
<script src="../assets/js/vue.js"></script>
</head>
<body>
<h1>componen-3 继承</h1>
<hr>
<div id="app">
<province></province>
</div>
<script>
var city={
template: `<div style="color:green;">word</div>`
}
var provinceComplate = {
template: `
<div style="color:red;">
hello
<city></city>
</div>
`,
components:{
'city':city
}
}
var app = new Vue({
el: '#app',
components: {
'province': provinceComplate
}
})
</script>
</body>
</html>