78 lines
2.0 KiB
HTML
78 lines
2.0 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">
|
|
|
|
<v-swiper :list="newsList">
|
|
<template #html="{ item }">
|
|
<img :src="item.src">
|
|
</template>
|
|
</v-swiper>
|
|
|
|
|
|
|
|
<v-swiper :list="dd">
|
|
<template #html="{ item }">
|
|
<a :href="item.href">{{ item.title }}</a>
|
|
</template>
|
|
</v-swiper>
|
|
|
|
</div>
|
|
</body>
|
|
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
|
|
<script>
|
|
|
|
Vue.component('v-swiper', {
|
|
// 存放html代码
|
|
template: `
|
|
<div class="swiper">
|
|
<li v-for="item,index in list">
|
|
<slot name="html" v-bind:item="item"></slot>
|
|
</li>
|
|
</div>
|
|
`,
|
|
props: {
|
|
list: {
|
|
default: () => [],
|
|
type: Array
|
|
}
|
|
},
|
|
data() {
|
|
return {
|
|
|
|
}
|
|
}
|
|
});
|
|
|
|
// 局部组件
|
|
var vm = new Vue({
|
|
el: '.app',
|
|
data: {
|
|
newsList: [
|
|
{ id: 1, title: '新闻1', src: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png' },
|
|
{ id: 2, title: '新闻2', src: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png' },
|
|
{ id: 3, title: '新闻3', src: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png' },
|
|
],
|
|
dd: [
|
|
{ id: 1, title: '新闻1', href: 'https://www.baidu.com' },
|
|
{ id: 2, title: '新闻2', href: 'https://cn.vuejs.org/v2/guide/components-slots.html#%E4%BD%9C%E7%94%A8%E5%9F%9F%E6%8F%92%E6%A7%BD' },
|
|
{ id: 3, title: '新闻3', href: 'https://www.bilibili.com/' },
|
|
]
|
|
},
|
|
mounted() {
|
|
},
|
|
methods: {
|
|
|
|
}
|
|
})
|
|
</script>
|
|
|
|
</html> |