73 lines
1.7 KiB
HTML
73 lines
1.7 KiB
HTML
<!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>
|
|
</head>
|
|
|
|
<body>
|
|
<div class="app">
|
|
|
|
<lb-header text="测试" :list-arr="newsList"></lb-header>
|
|
<div class="content">内容部分</div>
|
|
|
|
</div>
|
|
</body>
|
|
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
|
|
<script>
|
|
|
|
|
|
Vue.component('lb-header', {
|
|
template: `
|
|
<div class="header">
|
|
<h2>{{text}}</h2>
|
|
<ul>
|
|
<li v-for="item,index in listArr">{{item.title}}</li>
|
|
</ul>
|
|
<div class="right">
|
|
|
|
</div>
|
|
</div>
|
|
`,
|
|
props: {
|
|
text: {
|
|
default: '默认参数',
|
|
type: String,
|
|
required: true
|
|
},
|
|
listArr: {
|
|
default: () => [],
|
|
type: Array
|
|
}
|
|
},
|
|
data() {
|
|
return {
|
|
|
|
}
|
|
}
|
|
});
|
|
|
|
// 局部组件
|
|
var vm = new Vue({
|
|
el: '.app',
|
|
data: {
|
|
test: '你好',
|
|
title: '首页',
|
|
newsList: [
|
|
{ id: 1, title: '新闻1', href: 'https://www.baidu.com/' },
|
|
{ id: 2, title: '新闻2', href: 'https://www.baidu.com/' },
|
|
{ id: 3, title: '新闻3', href: 'https://www.baidu.com/' },
|
|
]
|
|
},
|
|
mounted() {
|
|
console.log("mounted");
|
|
console.log(this.test);
|
|
},
|
|
methods: {
|
|
|
|
}
|
|
})
|
|
</script>
|
|
</html> |