完成props的学习

new_branch1
roger 2 years ago
parent dfdde18ab2
commit f42eb51742
  1. 2
      19_单文件组件/index.html
  2. 40
      20_脚手架/vue_code/01.src_ref属性解析/App.vue
  3. BIN
      20_脚手架/vue_code/01.src_ref属性解析/assets/logo.png
  4. 24
      20_脚手架/vue_code/01.src_ref属性解析/components/School.vue
  5. 9
      20_脚手架/vue_code/01.src_ref属性解析/main.js
  6. 16
      20_脚手架/vue_code/02.src_props配置/App.vue
  7. BIN
      20_脚手架/vue_code/02.src_props配置/assets/logo.png
  8. 53
      20_脚手架/vue_code/02.src_props配置/components/Student.vue
  9. 9
      20_脚手架/vue_code/02.src_props配置/main.js
  10. 16
      20_脚手架/vue_code/src/App.vue
  11. 53
      20_脚手架/vue_code/src/components/Student.vue
  12. 9
      20_脚手架/vue_code/src/main.js

@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>联系单文件组件</title>
<title>单文件组件</title>
</head>
<body>
<div id="root"></div>

@ -0,0 +1,40 @@
<template>
<div>
<h2 v-text="msg" ref="title"></h2>
<h2 v-text="msg" id="title2"></h2>
<button @click="showDOM">点击打印上面DOM</button>
<School ref="sch"/>
<School id="sch2"/>
</div>
</template>
<script>
import School from "./components/School.vue";
export default {
name: "App",
components: {
School
},
data() {
return {
msg: "Hello!"
}
},
methods:{
showDOM() {
// htmlDOM
console.log("title", this.$refs.title)
// htmlDOM
console.log("title2", document.getElementById('title2'))
// VueComponent
console.log("sch", this.$refs.sch)
// htmlDOM
console.log("sch2", document.getElementById('sch2'))
}
}
}
</script>
<style scoped>
</style>

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

@ -0,0 +1,24 @@
<template>
<div class="school">
<h2>学校名称{{ name }}</h2>
<h2>学校地址{{ address }}</h2>
</div>
</template>
<script>
export default {
name: "School",
data() {
return {
name: "修仙学院",
address: "天山"
}
}
}
</script>
<style scoped>
.school {
background-color: gray
}
</style>

@ -0,0 +1,9 @@
import Vue from "vue";
import App from "./App";
new Vue({
components: {
App
},
render: h => h(App)
}).$mount('#app')

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

@ -0,0 +1,53 @@
<template>
<div>
<h1>{{ msg }}</h1>
<h2>学生名称{{ name }}</h2>
<h2>学生性别{{ sex }}</h2>
<h2>学生年龄{{ localAge + 1 }}</h2>
<button @click="changeAge">点击年龄+1</button>
</div>
</template>
<script>
export default {
name: "Student",
data() {
return {
msg: "欢迎",
localAge: this.age
}
},
methods: {
changeAge() {
this.localAge++
}
},
//
// 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
}
}
}
</script>

@ -0,0 +1,9 @@
import Vue from "vue";
import App from "./App";
new Vue({
components: {
App
},
render: h => h(App)
}).$mount('#app')

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

@ -0,0 +1,53 @@
<template>
<div>
<h1>{{ msg }}</h1>
<h2>学生名称{{ name }}</h2>
<h2>学生性别{{ sex }}</h2>
<h2>学生年龄{{ localAge + 1 }}</h2>
<button @click="changeAge">点击年龄+1</button>
</div>
</template>
<script>
export default {
name: "Student",
data() {
return {
msg: "欢迎",
localAge: this.age
}
},
methods: {
changeAge() {
this.localAge++
}
},
//
// 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
}
}
}
</script>

@ -0,0 +1,9 @@
import Vue from "vue";
import App from "./App";
new Vue({
components: {
App
},
render: h => h(App)
}).$mount('#app')
Loading…
Cancel
Save