diff --git a/20_脚手架/vue_code/09.自定义事件/App.vue b/20_脚手架/vue_code/09.自定义事件/App.vue
new file mode 100644
index 0000000..73ea2fe
--- /dev/null
+++ b/20_脚手架/vue_code/09.自定义事件/App.vue
@@ -0,0 +1,64 @@
+
+
+
{{ msg }}{{stuName}}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/20_脚手架/vue_code/09.自定义事件/assets/logo.png b/20_脚手架/vue_code/09.自定义事件/assets/logo.png
new file mode 100644
index 0000000..f3d2503
Binary files /dev/null and b/20_脚手架/vue_code/09.自定义事件/assets/logo.png differ
diff --git a/20_脚手架/vue_code/09.自定义事件/components/School.vue b/20_脚手架/vue_code/09.自定义事件/components/School.vue
new file mode 100644
index 0000000..6ccc0ae
--- /dev/null
+++ b/20_脚手架/vue_code/09.自定义事件/components/School.vue
@@ -0,0 +1,35 @@
+
+
+
学校名称:{{ name }}
+ 学校地址:{{ address }}
+
+
+
+
+
+
+
+
+
diff --git a/20_脚手架/vue_code/09.自定义事件/components/Student.vue b/20_脚手架/vue_code/09.自定义事件/components/Student.vue
new file mode 100644
index 0000000..f6ca56a
--- /dev/null
+++ b/20_脚手架/vue_code/09.自定义事件/components/Student.vue
@@ -0,0 +1,52 @@
+
+
+
学生名称:{{ name }}
+ 学生年龄:{{ age }}
+ 当前序号:{{number}}
+
+
+
+
+
+
+
+
+
+
+
diff --git a/20_脚手架/vue_code/09.自定义事件/main.js b/20_脚手架/vue_code/09.自定义事件/main.js
new file mode 100644
index 0000000..30ef712
--- /dev/null
+++ b/20_脚手架/vue_code/09.自定义事件/main.js
@@ -0,0 +1,16 @@
+// 引入Vue
+import Vue from "vue";
+// 引入App
+import App from "./App";
+
+// 设置Vue
+Vue.config.productionTip = false
+
+
+// 实例化Vue
+new Vue({
+ components: {
+ App
+ },
+ render: h => h(App)
+}).$mount('#app')
diff --git a/20_脚手架/vue_code/src/App.vue b/20_脚手架/vue_code/src/App.vue
index 59fdf92..73ea2fe 100644
--- a/20_脚手架/vue_code/src/App.vue
+++ b/20_脚手架/vue_code/src/App.vue
@@ -1,13 +1,14 @@
-
{{ msg }}
+ {{ msg }}{{stuName}}
-
+
+
-
+
@@ -23,7 +24,8 @@ export default {
},
data() {
return {
- msg: "Hello:"
+ msg: "Hello:",
+ stuName: ""
}
},
methods: {
@@ -32,12 +34,18 @@ export default {
},
getStudentName(name, ...params) {
console.log("getStudentName", name, params)
-
+ this.stuName = name
+ },
+ method1() {
+ console.log("demo自定义事件被调用!")
+ },
+ show() {
+ alert("组件点击事件")
}
},
mounted() {
// 正常写法
- this.$refs.student.$on("studentName", this.getStudentName)
+ // this.$refs.student.$on("studentName", this.getStudentName)
// 可以设置只执行一次
// 可以加延时
// this.$refs.student.$once("studentName", this.getStudentName)
diff --git a/20_脚手架/vue_code/src/components/Student.vue b/20_脚手架/vue_code/src/components/Student.vue
index 333d2b0..f6ca56a 100644
--- a/20_脚手架/vue_code/src/components/Student.vue
+++ b/20_脚手架/vue_code/src/components/Student.vue
@@ -2,7 +2,11 @@
学生名称:{{ name }}
学生年龄:{{ age }}
+ 当前序号:{{number}}
+
+
+
@@ -13,12 +17,26 @@ export default {
return {
name: "小强",
age: 18,
+ number: 0
}
},
methods: {
sendStudentName() {
// 触发Student组件实例上的studentName事件
this.$emit("studentName", this.name, 666, 777, 888)
+ this.$emit("demo")
+ },
+ unbind() {
+ // this.$off("studentName") // 解绑单个自定义事件
+ this.$off(["studentName", "demo"]) // 解绑多个自定义事件
+ this.$off() // 解绑全部自定义事件
+ },
+ death() {
+ this.$destroy() // 销毁当前Student组件的实例
+ },
+ num() {
+ console.log("num被调用")
+ this.number++
}
}
}