局部和全局组件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>局部和全局组件</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
</head>
<body>
<div id="app">
<input type="" v-model="txt">
<tanchuan1 :msg="txt">
</tanchuan1>
<input type="" v-model="t">
<tanchuan :msg="t" say="hhhh"></tanchuan>
</div>
</body>
<script type="text/javascript">
//全局组件
Vue.component(
'tanchuan',
{
// 传参数,变量。只能父传子
props: ['say', 'msg'],
template: '<h1>自定义组件!{{say}}{{msg}}</h1>'
}
)
//局部组件
var vm = new Vue({
components: {
'tanchuan1': {
props: ['msg'],
template: '<h1>自定义组件!{{msg}}</h1>'
},
},
el: '#app',
data: {
txt: "",
t: ""
},
})
</script>
</html>
效果图
