71 lines
1.5 KiB
HTML
71 lines
1.5 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>Document</title>
|
|
</head>
|
|
<div class="app">
|
|
<abc @change="getData" ></abc>
|
|
<!-- :x=" '2' " -->
|
|
<!-- <c></c>
|
|
<d></d> -->
|
|
</div>
|
|
|
|
<body>
|
|
|
|
</body>
|
|
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
|
|
<script>
|
|
Vue.component('abc', {
|
|
template: `
|
|
<div>
|
|
<h1>{{title}}</h1>
|
|
<h2 @click="submit">{{ x }}</h2>
|
|
</div>`,
|
|
data() {
|
|
return {
|
|
title: '我是全局组件',
|
|
list: "这是子组件的数据"
|
|
}
|
|
},
|
|
props: {
|
|
x: {
|
|
default: "这是默认标题",
|
|
type: String
|
|
}
|
|
},
|
|
methods: {
|
|
submit() {
|
|
this.$emit("change", this.list)
|
|
}
|
|
}
|
|
})
|
|
|
|
// var c = {
|
|
// template: `<h1>{{title}}</h1>`,
|
|
// data() {
|
|
// return {
|
|
// title: '我是局部组件',
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
new Vue({
|
|
el: ".app",
|
|
data: {},
|
|
methods: {
|
|
getData(val) {
|
|
console.log("父组件收到的数据:", val);
|
|
}
|
|
},
|
|
// components: {
|
|
// c,
|
|
// "d": c
|
|
// }
|
|
})
|
|
</script>
|
|
|
|
</html> |