完成props的学习

new_branch1
roger 2 years ago
parent f42eb51742
commit 287bc7dfc3
  1. 20
      20_脚手架/vue_code/03.src_mixin混入/App.vue
  2. BIN
      20_脚手架/vue_code/03.src_mixin混入/assets/logo.png
  3. 28
      20_脚手架/vue_code/03.src_mixin混入/components/School.vue
  4. 28
      20_脚手架/vue_code/03.src_mixin混入/components/Student.vue
  5. 16
      20_脚手架/vue_code/03.src_mixin混入/main.js
  6. 17
      20_脚手架/vue_code/03.src_mixin混入/mixin.js
  7. 6
      20_脚手架/vue_code/src/App.vue
  8. 28
      20_脚手架/vue_code/src/components/School.vue
  9. 49
      20_脚手架/vue_code/src/components/Student.vue
  10. 7
      20_脚手架/vue_code/src/main.js
  11. 17
      20_脚手架/vue_code/src/mixin.js

@ -0,0 +1,20 @@
<template>
<div>
<School/>
<Student/>
</div>
</template>
<script>
import School from "./components/School.vue";
import Student from "./components/Student.vue";
export default {
name: "App",
components: {
School,
Student
}
}
</script>

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

@ -0,0 +1,28 @@
<template>
<div>
<h2 @click="showName">学校名称{{ name }}</h2>
<h2>学校地址{{ address }}</h2>
</div>
</template>
<script>
//
// import {mixin_method1, mixin_method2} from "@/mixin";
export default {
name: "School",
data() {
return {
name: "修仙学院",
address: "长白山",
msg: "欢迎学校" // vc
}
},
mounted() {
console.log("欢迎学校") // mixinvc
},
//
// mixins: [mixin_method1, mixin_method2]
}
</script>

@ -0,0 +1,28 @@
<template>
<div>
<h2 @click="showName">学生名称{{ name }}</h2>
<h2>学生年龄{{ age }}</h2>
</div>
</template>
<script>
//
// import {mixin_method1, mixin_method2} from "../mixin";
export default {
name: "Student",
data() {
return {
name: "小强",
age: 18,
msg: "欢迎学生"
}
},
mounted() {
console.log("欢迎学生")
},
//
// mixins: [mixin_method1, mixin_method2]
}
</script>

@ -0,0 +1,16 @@
import Vue from "vue";
import App from "./App";
import {mixin_method1, mixin_method2} from "@/mixin";
Vue.config.productionTip = false
Vue.mixin(mixin_method1)
Vue.mixin(mixin_method2)
new Vue({
components: {
App
},
render: h => h(App)
}).$mount('#app')

@ -0,0 +1,17 @@
export const mixin_method1 = {
methods: {
showName() {
alert(this.name)
}
},
mounted() {
console.log("欢迎")
}
}
export const mixin_method2 = {
data() {
return {
msg: "欢迎"
}
}
}

@ -1,15 +1,19 @@
<template>
<div>
<Student name="小强" sex="男" :age="18"/>
<School/>
<Student/>
</div>
</template>
<script>
import School from "./components/School.vue";
import Student from "./components/Student.vue";
export default {
name: "App",
components: {
School,
Student
}
}

@ -0,0 +1,28 @@
<template>
<div>
<h2 @click="showName">学校名称{{ name }}</h2>
<h2>学校地址{{ address }}</h2>
</div>
</template>
<script>
//
// import {mixin_method1, mixin_method2} from "@/mixin";
export default {
name: "School",
data() {
return {
name: "修仙学院",
address: "长白山",
msg: "欢迎学校" // vc
}
},
mounted() {
console.log("欢迎学校") // mixinvc
},
//
// mixins: [mixin_method1, mixin_method2]
}
</script>

@ -1,53 +1,28 @@
<template>
<div>
<h1>{{ msg }}</h1>
<h2>学生名称{{ name }}</h2>
<h2>学生性别{{ sex }}</h2>
<h2>学生年龄{{ localAge + 1 }}</h2>
<button @click="changeAge">点击年龄+1</button>
<h2 @click="showName">学生名称{{ name }}</h2>
<h2>学生年龄{{ age }}</h2>
</div>
</template>
<script>
//
// import {mixin_method1, mixin_method2} from "../mixin";
export default {
name: "Student",
data() {
return {
msg: "欢迎",
localAge: this.age
name: "小强",
age: 18,
msg: "欢迎学生"
}
},
methods: {
changeAge() {
this.localAge++
}
mounted() {
console.log("欢迎学生")
},
//
// props: ['name', 'age', 'sex']
// ()
// props: {
// name: String,
// age: Number,
// sex: String
// }
//
props: {
name: {
type: String,
required: true,
},
age: {
type: Number,
default: 99
},
sex: {
type: String,
required: true
}
}
//
// mixins: [mixin_method1, mixin_method2]
}
</script>

@ -1,6 +1,13 @@
import Vue from "vue";
import App from "./App";
import {mixin_method1, mixin_method2} from "@/mixin";
Vue.config.productionTip = false
Vue.mixin(mixin_method1)
Vue.mixin(mixin_method2)
new Vue({
components: {
App

@ -0,0 +1,17 @@
export const mixin_method1 = {
methods: {
showName() {
alert(this.name)
}
},
mounted() {
console.log("欢迎")
}
}
export const mixin_method2 = {
data() {
return {
msg: "欢迎"
}
}
}
Loading…
Cancel
Save