props和$emit父子组件传值
父组件向子组件传值,通过props数组:
props 子组件获取父元素值 通过v-bind:parent=‘msg’ 再 props:[‘parent’]
<div id="app">
<com1 v-bind:chang="msg" @func="changMsg"></com1>
{
{list}}
</div>
<template id="tmp1">
<div>
<h1>这是子元素--{
{chang}}</h1>
<input type="button" name="" id="" @click="changChil" value="获取子元素中数据">
</div>
</template>
<script>
var com1={
template:`#tmp1`,
data(){
return{
msg:'我是子元素中内容'
}
},
props:['chang'],
methods:{
changChil(){
this.$emit('func',this.msg)
}
}
}
new