Files
2024-09-27 02:06:13 +08:00

147 lines
3.6 KiB
HTML

<!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="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div class="app">
<l-header @tzhaha="getChildren" :item-list="FList"></l-header>
<p> {{ UserName | test}}</p>
<h2 ref="sb">{{hello}}</h2>
<div class="name">
<input type="text" @input="checkUserName" v-check="UserName" v-model="UserName" placeholder="用户名">
<span>{{tips}}</span>
</div>
<l-foote>
<template v-slot:left>
<span>左边图标</span>
</template>
<template v-slot:right>
<span>我的</span>
</template>
</l-foote>
</div>
</body>
<script>
var PageParams = {
data: {
mixinsOne: 'mixinsOne',
params: {
page: 1,
limit: 10
}
},
}
Vue.component('l-foote',{
template: `
<div>
<slot name="left"></slot>
<l-header @tzhaha="test" :item-list="[3,4,5,6,7,8,9]">></l-header>
<h2>底部版权</h2>
<slot name="right"></slot>
</div>
`,
methods: {
test() {
alert("1111")
}
}
})
// 子组件
Vue.component('l-header',{
props: {
itemList: {
type: Array,
default: [1,2]
}
},
template: `<ul>
<li v-for="item in itemList">{{ item }}</li>
<button @click="TzFather">下一页</button>
</ul>`,
data() {
return {
list: ['344','3435','5668']
}
},
methods: {
TzFather() {
this.$emit("tzhaha",11)
}
}
})
// 父组件
// v-lb
vm = new Vue({
el: '.app',
mixins: [PageParams],
data: {
hello: '11',
UserName: 'dewrdewfeetgrttwefergrthr',
tips: '',
FList: ['09','sds','去的汪峰的']
},
filters: {
test(val) {
return val.substring(0,4)+"..."
}
},
directives: {
check: {
inserted(el, bind) {
console.log(bind);
document.title = bind.expression
}
}
},
beforeCreate() {
// console.log("beforeCreate");
// console.log(this.hello);
},
created() {
// console.log("111: ",this.$refs.sb);
// console.log(this.hello);
},
mounted() {
// console.log(this.$refs.sb);
// console.log(this.hello);
// this.mixins222()
},
methods: {
getChildren(val) {
alert("父组件收到的数值为:"+val)
},
checkUserName() {
if (this.UserName.length <6){
this.tips = "用户名不能少于6个字符"
} else {
this.tips = ""
}
}
},
watch: {
hello(newVal, oval) {
// console.log("newVal: ", newVal);
// console.log("oval: ", oval);
}
},
computed: {
test() {
return "22222"
}
}
})
</script>
</html>