Vue自定义复合组件

vue

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Document</title>

<script src="./js/vue.js"></script>

</head>

<body>

<div >

<parent></parent>

</div>

<script>

Vue.component('child-first',{

template:`

<h4>第一个孩子{{word}}</h4>

`,

data:function(){

return {

word: 'hello world!'

};

}

});

Vue.component('child-second',{

template:`

<div>

<h2>第二个孩子!</h2>

<div v-for="item in array">{{item}}</div>

</div>

`,

data:function(){

return {

array:['ab','bc','cd']

};

}

});

Vue.component('parent',{

template:`

<div>

<child-first></child-first>

<child-second></child-second>

</div>

`

})

var m = {

}

var vm = new Vue({

el:"#app",

data: m,

methods:{

}

})

</script>

</body>

</html>

以上是 Vue自定义复合组件 的全部内容, 来源链接: utcz.com/z/377994.html

回到顶部