1.父传子一次传两个变量mov 和 song
父组件 Father.vue
<template>
<div id="father">
<son v-bind:movoffather="mov" :songoffather="song">
</son>
</div>
</template>
<script>
import Son from "./Son";
export default {
name: "Father",
components:{
Son
},
data(){
return{
mov:['成龙','李连杰','李小龙'],
song:'我爱唱歌'
}
}
}
</script>
<style scoped>
</style>
props:['movoffather','songoffather']
key 的值可以是数组,字符串,对象
子组件 Son.vue
<template>
<div id =son>
<span>{{movoffather}}</span>
<br>
{{songoffather}}
</div>
</template>
<script>
export default {
name: "Son",
props:['movoffather','songoffather']
}
</script>
<style scoped>
</style>
运行结果
props的对象形式
props:{
uploadOption:{
type:Object, 参数类型必须是一个对象
required: true 这一种说明这个参数是必须的哈
}}
props: {
path: String,
activeColor: {
type: String,
default: 'red'
}
}
props: {
data: {
type: Array,
require: true
},
status: {
type: Boolean,
require: false
}
}
props: {
array: {
type: Array,
default: () => []
},
object: {
type: Object,
default: () => {}
}
}