码迷,mamicode.com
首页 > 其他好文 > 详细

vue父页面给子页面传递数据

时间:2018-05-30 00:22:59      阅读:663      评论:0      收藏:0      [点我收藏+]

标签:script   自定义   style   div   v-model   str   ber   数据类型   life   

父页面:

<template>
<div>{{msg}}
<Son title=‘向子文件传递数据‘ :data=‘data‘ :lifemsg =‘lifemsg‘ :num=‘num‘/>
<button @click="chageMsg">修改数据</button>
<input type="text" v-model="lifemsg" />
</div>

</template>

<script>
import Son from ‘./son‘
export default {
name: ‘mc‘,
data() {
return {
msg: ‘自定义‘,
data:‘我是父数据‘,
lifemsg:‘‘,
num:10

}
},
components:{
Son
},
methods:{
chageMsg(event){
this.data = ‘修改后的自定义‘
}
}
}
</script>
<!--scoped样式只在当前组件生效-->
<style scoped>

</style>

 

子页面:

<template>
<div><p>son {{title}},{{data}} </p>
<p>父页面传过来的:{{lifemsg}}</p>
<p>{{num}}</p>
</div>

</template>

<script>
export default {
name: ‘son‘,
data() {
return {
msg: ‘自定义‘

}
},
props:[‘title‘,‘data‘,‘lifemsg‘,‘num‘]
// props:{ //对父类的数据类型进行验证
// title:[String,Number]
// lifemsg:String,
// num:Number,
// data:{
// type:String,
// required:true
// }
// }
}
</script>

<style>

</style>

vue父页面给子页面传递数据

标签:script   自定义   style   div   v-model   str   ber   数据类型   life   

原文地址:https://www.cnblogs.com/qiyc/p/9108623.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!