Files
ClassContent/历届学生/逯帅帅/每日课程/2021-03-23/component.html
2024-09-27 02:06:13 +08:00

163 lines
3.1 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div class="app">
<h3>{{ '哈哈哈哈哈' | spl }}</h3>
<button @click="a">哈哈哈</button>
<lb-hello>
<template v-slot:back>
<h1>返回按钮</h1>
</template>
<template v-slot:action>
<h1>喜欢 和 分享</h1>
</template>
</lb-hello>
<lb-swiper @sclick="getData"></lb-swiper>
<h2>qdqwdwq</h2>
<lb-footer ref="footer" :footer-arr="tabs"></lb-footer>
</div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
// 组件?
// 就是使用频率搞的html代码块 js function
// 全局组件
// 局部组件
// 父子组件之间的数据传递
// 父 ---> 子 props
// 子 ---> 父 $emit
// 父 访问 子 的方法 $refs
// 反过来? 和 兄弟之间的相互访问 $parent $root
// 生命周期
Vue.component('lb-hello', {
template: `
<div>
<div class="back">
<slot name="back"></slot>
</div>
<h2>全局组件</h2>
<div class="action">
<slot name="action"></slot>
</div>
</div>
`,
data() {
return {}
},
methods: {}
})
var footer = {
template: `
<div>
<p>{{test}}</p>
<lb-hello></lb-hello>
<ul>
<li v-for="(item,index) in footerArr || footer">{{item.title}}</li>
</ul>
</div>
`,
props: {
footerArr: {
type: Array,
default: () => []
},
test: {
type: String,
default: '这默认数值'
}
},
data () {
return {
footer: [
{ title: '商城' },
{ title: '购物车' },
{ title: '订单' },
{ title: '返回首页' },
]
}
},
created() {
// console.log("======: ",this.$parent.$data.tabs)
console.log(this.$parent.$children[1])
},
methods: {
footertest() {
console.log("footer 子组件的方法")
}
}
};
var swiper = {
template: `
<button @click="setSata">点我</button>
`,
data() {
return {
arr: 'swiper的数据'
}
},
methods: {
setSata() {
this.$emit('sclick', this.arr)
}
}
}
// 代码片段
var mix = {
data () {
return {
page: 0,
totalPage: 100
}
},
methods: {
}
};
new Vue({
el: '.app',
mixins: [mix],
data: {
tabs: [
{ title: '首页' },
{ title: '门店' },
{ title: '商城' },
{ title: '我的' },
]
},
created() {
console.log(this.page)
},
methods: {
getData(res) {
console.log(res)
},
testf(res) {
console.log(res)
},
a () {
this.$refs.footer.footertest()
}
},
filters: {
spl(val) {
return val.substr(0,1)
}
},
components: {
'lb-footer':footer,
'lb-swiper':swiper,
}
})
</script>
</html>