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

父页面:

<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>

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

时间: 2024-08-03 12:19:40

vue父页面给子页面传递数据的相关文章

vue父组件向子组件传递数据

父组件 <template> <div id="app"> <v-header :childseller="fatherseller"></v-header> </div> </template> <script type="text/ecmascript-6"> import header from 'components/header/header.vue';

Vue父组件向子组件传递一个动态的值,子组件如何保持实时更新实时更新?

原文:https://blog.csdn.net/zhouweixue_vivi/article/details/78550738 2017年11月16日 14:22:50 zhouweixue_vivi 阅读数:29918 最近用vue做一个新项目,经历了各种折磨,每次遇到问题都想大喊,格劳资上JQuery,氮素肯定是不行的,今天遇到一个小问题,Vue父组件向子组件传递一个动态的值,子组件只能获取初始值,不能实时更新? 这就有点折磨人了,设想的是,父组件发生变化获取数据,动态传递给子组件,子组

vue组件-#构成组件-父组件向子组件传递数据

组件对于vue来说非常重要,学习学习了基础vue后,再回过头来把组件弄透! 一.概念 组件意味着协同工作,通常父子组件会是这样的关系:组件 A 在它的模版中使用了组件 B . 它们之间必然需要相互通信:父组件要给子组件传递数据,子组件需要将它内部发生的事情告知给父组件. 在 Vue.js 中,父子组件的关系可以总结为 props down, events up . 父组件通过 props 向下传递数据给子组件,子组件通过 events 给父组件发送消息. 看看它们是怎么工作的.        

Vue父组件向子组件传递方法(自定义方法)并且子组件向父组件传递数据

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" con

Vue父组件与子组件传递事件/调用事件

父组件: <template><div><div @click="openChild">弹弹弹,弹出子组件</div><childs ref="alert" @watchChild="parentReceive"></childs> <!--监听子组件绑定的方法--></div></template> <script>impor

VUE中父组件向子组件传递数据 props使用

VUE中,子组件是不能直接访问父组件的数据(一般来说,当然如果你要破坏原则也是可以),如下< <body> <div id="fathercomponent"> <ul> <li v-for="item in fatherdatas">{{item}}</li> <!--父组件可以访问它自己的数据--> </ul> <child-component></chi

vue 通过Prop向子组件传递数据

如何使用 第一步父组件App.vue中 <template> <div id="app"> <Users :users="users"></Users> </div> </template> <script> import Users from './components/Users' export default { name: 'App', data: function () {

父组件向子组件传递数据,子组件展示并更新 element-ui

<el-select v-model="currentAuditProcess" placeholder="请选择" @click.native="clickSearchAuditProcessList"> <el-option v-for="item in auditProcesses" :key="item.id" :label="item.name" :value

vue引入iframe的父页面向子页面传递数据

父页面 <template> <div> <el-button @click='btn(index)' :class="{'active':activeName2==index}" v-for="(item,index) in list" :key="index"> {{item.label}} </el-button> <iframe-tab :assid="assid"

js父页面调用子页面数据时,子页面通过父页面传过来的参数回调父页面具体方法

今天写代码时发现同一页面多个地方需要调用同一个子页面,如果多个方法调用时,同一子页面回调父页面方法则会出问题,所以查了下资料,让这个功能通用化,根据具体方法回调具体父页面方法,顺便总结一下,希望以后可以有用,或许可以帮助需要帮助的人 这里使用 eval() 函数 定义和用法 eval() 函数可计算某个字符串,并执行其中的的 JavaScript 代码. 父页面调用子页面的路径(子页面的路径)如下 http://localhoust:8080/oss-portlet/html/util/area