<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style>
</style>
<script src="./vue.js"></script>
</head>
<body>
<div id="root">
<cpn v-bind:c-movies="movies" :cmessage="message"></cpn> <!--如果这里去掉:cmessage="message",则cmessage为默认值default:"aaa"-->
</div>
<!--//这里要写成:c-M(m)ovies="movies",因为下面props里面时驼峰命名法cMovies-->
<template id="cpn">
<div >
<ul>
<li v-for="item in cMovies">{{item}}</li>
</ul>
<h2>{{cmessage}}</h2>
</div>
</template>
<script>
const cpn={
template:"#cpn",
// props:['cmovies','cmessage'],
props:{
//1.类型限制
//cmovies:Array,
//2.提供默认值
cmessage:{
type:String,
default:"aaa", //当没传这个变量时,默认为”aaa“
required:true //使该值必须传
},
//类型是对象或数组时,默认值必须是一个函数
cMovies:{
type:Array,
default(){ //默认值
return []
}
}
},
data(){
return {}
}
}
new Vue({
el:"#root",
data:{
movies:["哪咤闹海","海王","海贼王"],
message:"asd"
},
components:{
cpn //加强写法
},
methods:{
},
computed:{
},
filters:{ //过滤器
}
})
</script>
</body>
</html>